mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-09 15:19:07 +00:00
std.compress.lzma: fix unpacked size checking logic
This commit is contained in:
parent
722e066173
commit
980445f08b
1 changed files with 3 additions and 2 deletions
|
|
@ -226,18 +226,19 @@ pub const Decode = struct {
|
||||||
try ld.resetState(allocating.allocator, new_props);
|
try ld.resetState(allocating.allocator, new_props);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const expected_unpacked_size = accum.len + unpacked_size;
|
||||||
const start_count = n_read;
|
const start_count = n_read;
|
||||||
var range_decoder = try lzma.RangeDecoder.initCounting(reader, &n_read);
|
var range_decoder = try lzma.RangeDecoder.initCounting(reader, &n_read);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (accum.len >= unpacked_size) break;
|
if (accum.len >= expected_unpacked_size) break;
|
||||||
if (range_decoder.isFinished()) break;
|
if (range_decoder.isFinished()) break;
|
||||||
switch (try ld.process(reader, allocating, accum, &range_decoder, &n_read)) {
|
switch (try ld.process(reader, allocating, accum, &range_decoder, &n_read)) {
|
||||||
.more => continue,
|
.more => continue,
|
||||||
.finished => break,
|
.finished => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (accum.len != unpacked_size) return error.DecompressedSizeMismatch;
|
if (accum.len != expected_unpacked_size) return error.DecompressedSizeMismatch;
|
||||||
if (n_read - start_count != packed_size) return error.CompressedSizeMismatch;
|
if (n_read - start_count != packed_size) return error.CompressedSizeMismatch;
|
||||||
|
|
||||||
return n_read;
|
return n_read;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue