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 /core | |
| 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 'core')
| -rw-r--r-- | core/encoding/base32/base32.odin | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/core/encoding/base32/base32.odin b/core/encoding/base32/base32.odin index 34de2ff53..d272b32b8 100644 --- a/core/encoding/base32/base32.odin +++ b/core/encoding/base32/base32.odin @@ -153,15 +153,15 @@ decode :: proc( padding_count += 1 } - // Check for proper padding and length combinations - if padding_count > 0 { - // Verify no padding in the middle - for i := 0; i < data_len - padding_count; i += 1 { - if data[i] == byte(PADDING) { - return nil, .Malformed_Input - } + // Verify no padding in the middle + for i := 0; i < data_len - padding_count; i += 1 { + if data[i] == byte(PADDING) { + return nil, .Malformed_Input } + } + // Check for proper padding and length combinations + if padding_count > 0 { content_len := data_len - padding_count mod8 := content_len % 8 required_padding: int |