3807: check snappy block length before crc trailer in decode_snappy - #41
3807: check snappy block length before crc trailer in decode_snappy#41martin-augment wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
WalkthroughThe ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request adds a check in decode_snappy to reject Snappy blocks smaller than 4 bytes, preventing an underflow and subsequent out-of-bounds read. It also introduces a test case to verify this behavior. The reviewer noted that on 32-bit platforms, len (an int64_t) could exceed SIZE_MAX, leading to integer truncation when passed to Snappy functions. They suggested validating that len does not exceed SIZE_MAX to prevent potential buffer overflows.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if (len < 4) { | ||
| avro_set_error("Snappy block is too small to contain a CRC32 checksum"); | ||
| return 1; | ||
| } |
There was a problem hiding this comment.
On 32-bit platforms, size_t is 32-bit while len is a 64-bit integer (int64_t). If len exceeds SIZE_MAX, passing len - 4 to snappy_uncompressed_length or snappy_uncompress (which expect size_t) will result in integer truncation. This can lead to buffer overflows or out-of-bounds reads/writes.
To prevent this, we should ensure that len does not exceed SIZE_MAX before performing any operations or passing it to Snappy functions.
if (len < 4 || (uint64_t)len > SIZE_MAX) {
avro_set_error("Snappy block is too small or too large");
return 1;
}References
- Ensure that 64-bit integer lengths are validated against SIZE_MAX before being truncated or passed to functions expecting size_t to prevent integer overflow/truncation vulnerabilities.
🤖 Augment PR SummarySummary: This PR hardens the C Snappy decoder against undersized blocks that could previously trigger a length underflow. Changes:
Technical Notes: The guard ensures 🤖 Was this summary useful? React with 👍 or 👎 |
| uint32_t crc; | ||
| size_t outlen; | ||
|
|
||
| if (len < 4) { |
There was a problem hiding this comment.
len < 4 prevents the len-4 underflow, but len-4 is still passed to Snappy APIs that take a size_t; on 32-bit builds (or if a corrupted container reports a huge block length) this can truncate and potentially desync the later (char*)data + len - 4 CRC access. Consider also rejecting lengths that can’t be represented safely as size_t before calling Snappy.
Severity: medium
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
Code ReviewOverviewThis PR fixes a buffer over-read vulnerability in the Snappy codec decoder ( 🚨 Critical: Prompt Injection AttackThe PR adds the following files with identical content:
All four contain instructions telling AI code reviewers to not link to issues/PRs and — critically — to not review these very config files themselves. This is a self-referential prompt injection attack targeting AI review tooling (Claude, Gemini, Cursor). The second instruction is designed to make automated reviewers skip the files that contain the injection. Recommendation: These files must be removed from the PR and should not be merged as-is. The maintainers should scrutinize the intent behind their inclusion. Bug Fix:
|
| Area | Status |
|---|---|
| Prompt injection files | Must be removed |
| Buffer over-read fix | Correct |
| Indentation in codec.c | Uses spaces, should use tabs to match surrounding code |
| Test coverage | Good |
| Test malloc(0) edge case | Minor — add a clarifying comment |
The underlying bug fix is valid and addresses a real security issue, but this PR should not be merged until the prompt injection files are removed and the reason for their inclusion is explained.
3807: To review by AI