From d802a4e9fa412e1234a5970b8545994293946409 Mon Sep 17 00:00:00 2001 From: Zoltán Kéri Date: Sat, 27 Dec 2025 04:30:37 +0100 Subject: encoding/base32: Fix padding validation for malformed input Fix a bug where padding characters in the middle of input were not detected when there was no trailing padding. The "verify no padding in middle" check was inside `if padding_count > 0`, so inputs like "MZ===YTBMZXW6YTB" would incorrectly pass validation. Test case added for this edge case. --- tests/core/encoding/base32/base32.odin | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/core/encoding/base32/base32.odin b/tests/core/encoding/base32/base32.odin index f757e99e5..2abb244ca 100644 --- a/tests/core/encoding/base32/base32.odin +++ b/tests/core/encoding/base32/base32.odin @@ -1,4 +1,3 @@ -#+test package test_encoding_base32 import "core:testing" @@ -83,7 +82,16 @@ test_base32_decode_invalid :: proc(t: ^testing.T) { // Section 3.2 - Padding requirements { - // Padding must only be at end + // Padding in middle without trailing padding + input := "MZ===YTBMZXW6YTB" // '===' in middle, no trailing padding + output, err := base32.decode(input) + if output != nil { + defer delete(output) + } + testing.expect_value(t, err, Error.Malformed_Input) + } + { + // Padding must only be at end (with trailing padding) input := "MZ=Q====" output, err := base32.decode(input) if output != nil { @@ -228,4 +236,4 @@ test_base32_custom_alphabet :: proc(t: ^testing.T) { } testing.expect_value(t, err, Error.Invalid_Character) } -} \ No newline at end of file +} -- cgit v1.2.3