Fix a integer overflow error caused by the small zstd decompression buffer size#54
Fix a integer overflow error caused by the small zstd decompression buffer size#54jiacai2050 merged 1 commit intojiacai2050:mainfrom
Conversation
Summary of ChangesHello @qilme, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical integer overflow error that could occur during Zstandard decompression. The issue stemmed from an undersized static buffer, which has now been replaced with a dynamically calculated size based on Zstandard's specifications. This change enhances the stability and reliability of the decompression process, preventing potential data corruption or application crashes. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request fixes an issue in zstd decompression by increasing the buffer size, correctly using constants from the zstd library. However, the new buffer is over 8MB and is allocated on the stack, which will likely cause a stack overflow. My review includes a critical suggestion to allocate this buffer on the heap instead, preventing the crash.
src/bin/zigfetch.zig
Outdated
| var buf: [std.compress.zstd.default_window_len + std.compress.zstd.block_size_max]u8 = undefined; | ||
| var dcp = std.compress.zstd.Decompress.init(&reader, &buf, .{}); |
There was a problem hiding this comment.
The new buffer size is over 8MB. Allocating this on the stack will likely cause a stack overflow. It should be allocated on the heap using the allocator passed to this function.
My suggestion heap-allocates the buffer and defers freeing it to prevent a memory leak.
var buf = try allocator.alloc(u8, std.compress.zstd.default_window_len + std.compress.zstd.block_size_max); defer allocator.free(buf);
var dcp = std.compress.zstd.Decompress.init(&reader, buf, .{});
|
When i fetch a tar.zst dep, |
|
Here
which is what i modified |
|
Zig repo's is written like this: |
No description provided.