diff options
| author | Zoltán Kéri <z@zolk3ri.name> | 2025-12-27 04:30:37 +0100 |
|---|---|---|
| committer | Zoltán Kéri <z@zolk3ri.name> | 2025-12-27 04:30:37 +0100 |
| commit | d802a4e9fa412e1234a5970b8545994293946409 (patch) | |
| tree | a5b4119b1c77754d7843c362ed7405559019d5d9 /tests | |
| parent | 2e6554b8c85c904eb1eb010f0312641be800823f (diff) | |
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.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/core/encoding/base32/base32.odin | 14 |
1 files changed, 11 insertions, 3 deletions
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 +} |