authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-10-04 11:47:59+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-10-07 00:29:48+02:00
logc6044e6a109aa3a01eb9daadb13c6256b80e853c
tree0757f2b9f5b3834866e2b4622442e4b32a93793a
parent4465f34532491c3c185c3ee6008a00a8c907abf9
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

base64: properly compute the decoded size upper bound

First, the correct length for decoding should be computed with /4*3 , not the other way round as when encoding. But also, without padding, a string such as "Zg" is valid base64 (here, it's the character 'f', padded base64 would be "Zg=="). decodedLenUpperBound() returned 0 instead of 1 in that example. Correctly fix the computation of the upper bound.

1 files changed, 1 insertions(+), 1 deletions(-)

lib/std/crypto/codecs/base64_hex_ct.zig+1-1
......@@ -261,7 +261,7 @@ pub const base64 = struct {
261261
262262 /// Returns the maximum possible decoded size for a given input length after skipping ignored characters.
263263 pub fn decodedLenUpperBound(b64_len: usize) usize {
264 return b64_len / 3 * 4;
264 return b64_len / 4 * 3 + (b64_len % 4) * 3 / 4;
265265 }
266266 };
267267