authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-10-04 17:09:47+02:00
committergravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-10-16 08:22:49+02:00
logb423f7b7b6da6f88301b14eaed5f9f8a4924847c
tree187d95955a0f33c6c0c87ed40acb96b05ac8baf0
parentbd51e91a9a934c915219b985549bb4fc060c0357

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.

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

lib/std/base64.zig+8-2
...@@ -31,6 +31,9 @@ pub const standard_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopq...@@ -31,6 +31,9 @@ pub const standard_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopq
31fn standardBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore {31fn standardBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore {
32 return Base64DecoderWithIgnore.init(standard_alphabet_chars, '=', ignore);32 return Base64DecoderWithIgnore.init(standard_alphabet_chars, '=', ignore);
33}33}
34fn standardNoPadBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore {
35 return Base64DecoderWithIgnore.init(standard_alphabet_chars, null, ignore);
36}
3437
35/// Standard Base64 codecs, with padding, as defined in38/// Standard Base64 codecs, with padding, as defined in
36/// [RFC 4648 section 4](https://datatracker.ietf.org/doc/html/rfc4648#section-4).39/// [RFC 4648 section 4](https://datatracker.ietf.org/doc/html/rfc4648#section-4).
...@@ -47,7 +50,7 @@ pub const standard = Codecs{...@@ -47,7 +50,7 @@ pub const standard = Codecs{
47pub const standard_no_pad = Codecs{50pub const standard_no_pad = Codecs{
48 .alphabet_chars = standard_alphabet_chars,51 .alphabet_chars = standard_alphabet_chars,
49 .pad_char = null,52 .pad_char = null,
50 .decoderWithIgnore = standardBase64DecoderWithIgnore,53 .decoderWithIgnore = standardNoPadBase64DecoderWithIgnore,
51 .Encoder = Base64Encoder.init(standard_alphabet_chars, null),54 .Encoder = Base64Encoder.init(standard_alphabet_chars, null),
52 .Decoder = Base64Decoder.init(standard_alphabet_chars, null),55 .Decoder = Base64Decoder.init(standard_alphabet_chars, null),
53};56};
...@@ -56,6 +59,9 @@ pub const standard_no_pad = Codecs{...@@ -56,6 +59,9 @@ pub const standard_no_pad = Codecs{
56/// [RFC 4648 section 5](https://datatracker.ietf.org/doc/html/rfc4648#section-5).59/// [RFC 4648 section 5](https://datatracker.ietf.org/doc/html/rfc4648#section-5).
57pub const url_safe_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".*;60pub const url_safe_alphabet_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".*;
58fn urlSafeBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore {61fn urlSafeBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore {
62 return Base64DecoderWithIgnore.init(url_safe_alphabet_chars, '=', ignore);
63}
64fn urlSafeNoPadBase64DecoderWithIgnore(ignore: []const u8) Base64DecoderWithIgnore {
59 return Base64DecoderWithIgnore.init(url_safe_alphabet_chars, null, ignore);65 return Base64DecoderWithIgnore.init(url_safe_alphabet_chars, null, ignore);
60}66}
6167
...@@ -74,7 +80,7 @@ pub const url_safe = Codecs{...@@ -74,7 +80,7 @@ pub const url_safe = Codecs{
74pub const url_safe_no_pad = Codecs{80pub const url_safe_no_pad = Codecs{
75 .alphabet_chars = url_safe_alphabet_chars,81 .alphabet_chars = url_safe_alphabet_chars,
76 .pad_char = null,82 .pad_char = null,
77 .decoderWithIgnore = urlSafeBase64DecoderWithIgnore,83 .decoderWithIgnore = urlSafeNoPadBase64DecoderWithIgnore,
78 .Encoder = Base64Encoder.init(url_safe_alphabet_chars, null),84 .Encoder = Base64Encoder.init(url_safe_alphabet_chars, null),
79 .Decoder = Base64Decoder.init(url_safe_alphabet_chars, null),85 .Decoder = Base64Decoder.init(url_safe_alphabet_chars, null),
80};86};