Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memcpy alias bug in std.compress.lzma #21447

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Szwagi
Copy link
Contributor

@Szwagi Szwagi commented Sep 18, 2024

Replaces memcpy with mem.copyForwards to prevent overlap panic.

thread 18216 panic: @memcpy arguments alias
C:\Program Files\Zig\lib\std\compress\lzma.zig:80:53: 0x18c72d in read (lzma.exe.obj)
            @memcpy(input[0 .. input.len - n], input[n..]);

The lzma tests never triggered the bug, I assume the inputs are too small so readAllAlloc never calls .read() for less than half of the buffer length, so if needed I attach some compressed input that does (let me know if I should get a minimal input that reproduces the issue and add a test).

test "lzma big file" {
    const allocator = std.testing.allocator;
    
    const compressed_file = try std.fs.cwd().openFile("compressed.txt", .{});
    defer compressed_file.close();

    var decompressor = try std.compress.lzma.decompress(allocator, compressed_file.reader());
    defer decompressor.deinit();
    
    var buffer = [1]u8{0};
    _ = try decompressor.read(buffer[0..]);
}

compressed.txt
expected.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant