commit f07bea20dab813fa1b25c3b3a7abe2fc8c992132 (tree)
parent 97b97ae6202811e207196920018c3b9610957f90
Author: Andrew Kelley <andrew@ziglang.org>
Date: Tue, 21 Jan 2025 18:37:28 -0500
Merge pull request #21447 from Szwagi/fix-lzma-memcpy-alias
Fix memcpy alias bug in std.compress.lzma
Diffstat:
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/lib/std/compress/lzma.zig b/lib/std/compress/lzma.zig
@@ -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;
}
diff --git a/lib/std/compress/lzma/test.zig b/lib/std/compress/lzma/test.zig
@@ -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..]);
+}