| author | |
| committer | |
| log | 98547713a354efef406ca79731db8984eb26c051 |
| tree | d0af6057b62cfc741d8d9313ac7e67e2abcde1d8 |
| parent | ee85c8b6d05dbda541d4b0b8b402aafad8e582a3 |
Previously, index out-of-bounds could occur when copying match_length bytes while decoding whatever sequence happened to overflow `dest`. Now, each sequence checks that there is enough room for the full sequence_length (literal_length + match_length) before doing any copying.
Fixes the failing inputs found here: https://github.com/ziglang/zig/issues/24817#issuecomment-31929277151 files changed, 3 insertions(+), 0 deletions(-)
lib/std/compress/zstd/Decompress.zig+3| ... | ... | @@ -765,6 +765,9 @@ pub const Frame = struct { |
| 765 | 765 | const match_length: usize = sequence.match_length; |
| 766 | 766 | const sequence_length = literal_length + match_length; |
| 767 | 767 | |
| 768 | if (sequence_length > dest[write_pos..].len) | |
| 769 | return error.MalformedSequence; | |
| 770 | ||
| 768 | 771 | const copy_start = std.math.sub(usize, write_pos + sequence.literal_length, sequence.offset) catch |
| 769 | 772 | return error.MalformedSequence; |
| 770 | 773 |