Merge pull request #21447 from Szwagi/fix-lzma-memcpy-alias

Fix memcpy alias bug in std.compress.lzma
This commit is contained in:
Andrew Kelley 2025-01-21 18:37:28 -05:00 committed by GitHub
commit f07bea20da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View file

@ -77,7 +77,7 @@ pub fn Decompress(comptime ReaderType: type) type {
const input = self.to_read.items;
const n = @min(input.len, output.len);
@memcpy(output[0..n], input[0..n]);
@memcpy(input[0 .. input.len - n], input[n..]);
std.mem.copyForwards(u8, input[0 .. input.len - n], input[n..]);
self.to_read.shrinkRetainingCapacity(input.len - n);
return n;
}

View file

@ -87,3 +87,13 @@ test "too small uncompressed size in header" {
@embedFile("testdata/bad-too_small_size-without_eopm-3.lzma"),
);
}
test "reading one byte" {
const compressed = @embedFile("testdata/good-known_size-with_eopm.lzma");
var stream = std.io.fixedBufferStream(compressed);
var decompressor = try lzma.decompress(std.testing.allocator, stream.reader());
defer decompressor.deinit();
var buffer = [1]u8{0};
_ = try decompressor.read(buffer[0..]);
}