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. --- core/encoding/base32/base32.odin | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'core/encoding') 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 -- cgit v1.2.3