From b423f7b7b6da6f88301b14eaed5f9f8a4924847c Mon Sep 17 00:00:00 2001 From: Frank Denis <124872+jedisct1@users.noreply.github.com> Date: Sun, 4 Oct 2026 17:09:47 +0200 Subject: [PATCH] std.base64: fix bogus decoderWithIgnore() definitions standard_no_pad.decoderWithIgnore() constructed a decoder with padding enabled, so it would accept padded base64 even when the decoder was explicitly configured to reject padding. And url_safe.decoderWithIgnore() constructed a decoder without padding, so it would accept unpadded URL-safe Base64 even when we require padding. --- lib/std/base64.zig | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/std/base64.zig b/lib/std/base64.zig index 8b90617c4130b3d7d8e3180fcc45a894fc3f099a..e9e3896c73ed52caacbccbe74bd010a2a01a4af5 100644 --- a/lib/std/base64.zig +++ b/lib/std/base64.zig @@ -31,6 +31,9 @@ pub const standard_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopq fn standardBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore { return Base64DecoderWithIgnore.init(standard_alphabet_chars, '=', ignore); } +fn standardNoPadBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore { + return Base64DecoderWithIgnore.init(standard_alphabet_chars, null, ignore); +} /// Standard Base64 codecs, with padding, as defined in /// [RFC 4648 section 4](https://datatracker.ietf.org/doc/html/rfc4648#section-4). @@ -47,7 +50,7 @@ pub const standard = Codecs{ pub const standard_no_pad = Codecs{ .alphabet_chars = standard_alphabet_chars, .pad_char = null, - .decoderWithIgnore = standardBase64DecoderWithIgnore, + .decoderWithIgnore = standardNoPadBase64DecoderWithIgnore, .Encoder = Base64Encoder.init(standard_alphabet_chars, null), .Decoder = Base64Decoder.init(standard_alphabet_chars, null), }; @@ -56,6 +59,9 @@ pub const standard_no_pad = Codecs{ /// [RFC 4648 section 5](https://datatracker.ietf.org/doc/html/rfc4648#section-5). pub const url_safe_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".*; fn urlSafeBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore { + return Base64DecoderWithIgnore.init(url_safe_alphabet_chars, '=', ignore); +} +fn urlSafeNoPadBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore { return Base64DecoderWithIgnore.init(url_safe_alphabet_chars, null, ignore); } @@ -74,7 +80,7 @@ pub const url_safe = Codecs{ pub const url_safe_no_pad = Codecs{ .alphabet_chars = url_safe_alphabet_chars, .pad_char = null, - .decoderWithIgnore = urlSafeBase64DecoderWithIgnore, + .decoderWithIgnore = urlSafeNoPadBase64DecoderWithIgnore, .Encoder = Base64Encoder.init(url_safe_alphabet_chars, null), .Decoder = Base64Decoder.init(url_safe_alphabet_chars, null), }; -- 2.54.0