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 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-10-06 10:44:11+02:00
logfc9184e652990545e3b00b04852eff3e522538e1
tree92cd8a07e530655129937bdf94c1249def22df2c
parent54460688aeb62584186e2fd3cb8998a8fa349c09

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 {...@@ -261,7 +261,7 @@ pub const base64 = struct {
261261
262 /// Returns the maximum possible decoded size for a given input length after skipping ignored characters.262 /// Returns the maximum possible decoded size for a given input length after skipping ignored characters.
263 pub fn decodedLenUpperBound(b64_len: usize) usize {263 pub fn decodedLenUpperBound(b64_len: usize) usize {
264 return b64_len / 3 * 4;264 return b64_len / 4 * 3 + (b64_len % 4) * 3 / 4;
265 }265 }
266 };266 };
267267