Skip to content

zstd: Validate SnappyConverter literal copies - #1170

Merged
klauspost merged 1 commit into
masterfrom
prevent-oob-reads
Jul 17, 2026
Merged

klauspost merged 1 commit into
masterfrom
prevent-oob-reads

Conversation

@klauspost

@klauspost klauspost commented Jul 17, 2026 •

Copy link
Copy Markdown
Owner

Enable disabled length check on SnappyConverter.Convert that could result in out-of-bounds reads buffer reads - or in case or re-use return values from the previous run.

Reported by @mfazrinizar

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of malformed Snappy data with invalid literal lengths.
    • Corrupt compressed blocks are now rejected reliably instead of potentially reading leftover data.
  • Tests

    • Added regression coverage for malformed blocks that declare more data than is available.

Enable disabled length check on `SnappyConverter.Convert` that could result in out-of-bounds reads buffer reads - or in case or re-use return values from the previous run.

Reported by @mfazrinizar
@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7dc8f856-c356-452f-a607-5875178f4aee

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between e29d4d3 and 837c4da.

πŸ“’ Files selected for processing (2)
  • zstd/snappy.go
  • zstd/snappy_test.go

πŸ“ Walkthrough

Walkthrough

Snappy literal decoding now validates that declared literal data fits within the remaining input. A regression test verifies malformed blocks return ErrSnappyCorrupt when a shared converter could otherwise encounter stale buffer data.

Changes

Snappy literal validation

Layer / File(s) Summary
Validate literal bounds and malformed-block handling
zstd/snappy.go, zstd/snappy_test.go
decodeSnappy rejects literal lengths exceeding the remaining input, and TestSnappy_ConvertMalformedLiteralStale verifies the converter returns ErrSnappyCorrupt for malformed blocks.

Estimated code review effort: 2 (Simple) | ~10 minutes

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title clearly matches the main change: adding validation around SnappyConverter literal handling.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check βœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check βœ… Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
πŸ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch prevent-oob-reads

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.

❀️ Share

Comment @coderabbitai help to get the list of available commands.

@klauspost
klauspost merged commit 9960386 into master Jul 17, 2026
27 checks passed
@klauspost
klauspost deleted the prevent-oob-reads branch July 17, 2026 09:10
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