Skip to content

Commit 2456267

Browse files
committed
Fix some base64 bugs
1 parent f18ed94 commit 2456267

File tree

2 files changed

+3
-18
lines changed

2 files changed

+3
-18
lines changed

src/forgiving_base64.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ impl<F, E> Decoder<F, E> where F: FnMut(&[u8]) -> Result<(), E> {
7171
// A character that’s not part of the alphabet
7272

7373
// Remove ASCII whitespace
74-
// '\t' | '\n' | '\r' was already filtered by decode_without_base64()
75-
if byte == b' ' || byte == b'\x0C' {
74+
if matches!(byte, b' ' | b'\t' | b'\n' | b'\r' | b'\x0C') {
7675
continue
7776
}
7877

@@ -88,7 +87,8 @@ impl<F, E> Decoder<F, E> where F: FnMut(&[u8]) -> Result<(), E> {
8887
}
8988
self.bit_buffer <<= 6;
9089
self.bit_buffer |= value as u32;
91-
if self.buffer_bit_length < 24 {
90+
// 18 before incrementing means we’ve just reached 24
91+
if self.buffer_bit_length < 18 {
9292
self.buffer_bit_length += 6;
9393
} else {
9494
// We’ve accumulated four times 6 bits, which equals three times 8 bits.

tests/wpt.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,9 @@ fn collect_base64<F>(add_test: &mut F)
8989
};
9090

9191
let should_panic = [
92-
" \t\n\u{c}\r ab\t\n\u{c}\r cd\t\n\u{c}\r ",
93-
" abcd",
94-
"////A",
95-
"///A",
96-
"AAA/",
97-
"AAAA/",
98-
"ab cd",
9992
"ab==",
100-
"ab\ncd",
101-
"ab\rcd",
10293
"ab\t\n\u{c}\r =\t\n\u{c}\r =\t\n\u{c}\r ",
103-
"ab\t\n\u{c}\r cd",
104-
"ab\tcd",
105-
"ab\u{c}cd",
10694
"abc=",
107-
"abcd ",
108-
"abcd",
109-
"abcde",
11095
].contains(&&*input);
11196
add_test(
11297
format!("base64 {:?}", input),

0 commit comments

Comments
 (0)