Skip to content

Commit 9f931a7

Browse files
committed
Do not allow empty chunk sizes
A chunk size must have at least one hex digit. If there are no hex digits at all, the chunk size is invalid.
1 parent 80a59e8 commit 9f931a7

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,8 @@ pub fn parse_chunk_size(buf: &[u8])
13091309
size *= RADIX;
13101310
size += (b + 10 - b'A') as u64;
13111311
}
1312+
// A chunk size must have at least one hex digit.
1313+
_ if count < 1 => return Err(InvalidChunkSize),
13121314
b'\r' => {
13131315
match next!(bytes) {
13141316
b'\n' => break,
@@ -2026,7 +2028,7 @@ mod tests {
20262028

20272029
#[test]
20282030
fn chunk_size_no_hex_digits() {
2029-
assert_eq!(parse_chunk_size(b"\r\n"), Ok(Status::Complete((2, 0))));
2031+
assert_eq!(parse_chunk_size(b"\r\n"), Err(crate::InvalidChunkSize));
20302032
}
20312033

20322034
#[test]

0 commit comments

Comments
 (0)