| ... | @@ -117,7 +117,7 @@ pub const Base64Encoder = struct { | ... | @@ -117,7 +117,7 @@ pub const Base64Encoder = struct { |
| 117 | out_idx += 1; | 117 | out_idx += 1; |
| 118 | } | 118 | } |
| 119 | if (encoder.pad_char) |pad_char| { | 119 | if (encoder.pad_char) |pad_char| { |
| 120 | for (dest[out_idx..]) |*pad| { | 120 | for (dest[out_idx..out_len]) |*pad| { |
| 121 | pad.* = pad_char; | 121 | pad.* = pad_char; |
| 122 | } | 122 | } |
| 123 | } | 123 | } |
| ... | @@ -305,6 +305,20 @@ test "base64" { | ... | @@ -305,6 +305,20 @@ test "base64" { |
| 305 | comptime try testAllApis(standard, "comptime", "Y29tcHRpbWU="); | 305 | comptime try testAllApis(standard, "comptime", "Y29tcHRpbWU="); |
| 306 | } | 306 | } |
| 307 | | 307 | |
| | 308 | test "base64 padding dest overflow" { |
| | 309 | const input = "foo"; |
| | 310 | |
| | 311 | var expect: [128]u8 = undefined; |
| | 312 | std.mem.set(u8, &expect, 0); |
| | 313 | _ = url_safe.Encoder.encode(expect[0..url_safe.Encoder.calcSize(input.len)], input); |
| | 314 | |
| | 315 | var got: [128]u8 = undefined; |
| | 316 | std.mem.set(u8, &got, 0); |
| | 317 | _ = url_safe.Encoder.encode(&got, input); |
| | 318 | |
| | 319 | try std.testing.expectEqualSlices(u8, &expect, &got); |
| | 320 | } |
| | 321 | |
| 308 | test "base64 url_safe_no_pad" { | 322 | test "base64 url_safe_no_pad" { |
| 309 | @setEvalBranchQuota(8000); | 323 | @setEvalBranchQuota(8000); |
| 310 | try testBase64UrlSafeNoPad(); | 324 | try testBase64UrlSafeNoPad(); |