| ... | @@ -578,7 +578,7 @@ fn peekBitsShortEnding(d: *Decompress, n: u4) !u16 { | ... | @@ -578,7 +578,7 @@ fn peekBitsShortEnding(d: *Decompress, n: u4) !u16 { |
| 578 | } | 578 | } |
| 579 | | 579 | |
| 580 | fn tossBitsShort(d: *Decompress, n: u4) !void { | 580 | fn tossBitsShort(d: *Decompress, n: u4) !void { |
| 581 | if (d.input.bufferedLen() * 8 + d.consumed_bits < n) return error.EndOfStream; | 581 | if (d.input.bufferedLen() * 8 - d.consumed_bits < n) return error.EndOfStream; |
| 582 | d.tossBits(n); | 582 | d.tossBits(n); |
| 583 | } | 583 | } |
| 584 | | 584 | |
| ... | @@ -1064,6 +1064,15 @@ test "bug 18966" { | ... | @@ -1064,6 +1064,15 @@ test "bug 18966" { |
| 1064 | ); | 1064 | ); |
| 1065 | } | 1065 | } |
| 1066 | | 1066 | |
| | 1067 | test "truncated input ending when reading dynamic length bits" { |
| | 1068 | try testFailure(.raw, &[_]u8{ |
| | 1069 | 0x15, 0xd5, 0x07, 0x3b, 0x16, 0x0c, 0x03, 0x86, |
| | 1070 | 0x61, 0x2b, 0xa3, 0xec, 0xec, 0x15, 0x95, 0x6c, |
| | 1071 | 0x92, 0x4d, 0x19, 0x95, 0x4a, 0xb6, 0x22, 0x23, |
| | 1072 | 0xc9, |
| | 1073 | }, error.EndOfStream); |
| | 1074 | } |
| | 1075 | |
| 1067 | test "reading into empty buffer" { | 1076 | test "reading into empty buffer" { |
| 1068 | // Inspired by https://github.com/ziglang/zig/issues/19895 | 1077 | // Inspired by https://github.com/ziglang/zig/issues/19895 |
| 1069 | const input = &[_]u8{ | 1078 | const input = &[_]u8{ |