Skip to content

Validate 7z next header bounds before allocation - #1430

Merged
adamhathcock merged 1 commit into
releasefrom
fix/7z-next-header-bounds
Oct 9, 2026
Merged

adamhathcock merged 1 commit into
releasefrom
fix/7z-next-header-bounds

Conversation

@adamhathcock

Copy link
Copy Markdown
Owner

This pull request adds robust validation to prevent reading past the end of a 7z archive when parsing the next header, addressing a potential security and reliability issue. It also introduces comprehensive unit tests to verify both sync and async code paths for these edge cases.

Header validation improvements:

  • Added a check in both ArchiveReader.ReadDatabase and ArchiveReader.ReadDatabaseAsync to ensure the next header does not extend beyond the end of the stream, throwing an IncompleteArchiveException if the check fails. This prevents potential out-of-bounds memory allocation and improves archive integrity validation. [1] [2]

Test coverage:

  • Introduced a new test class SevenZipHeaderValidationTests to verify that truncated or invalid next headers are detected early, and that valid edge cases are handled correctly, in both synchronous and asynchronous scenarios.

Copilot AI balanced review requested due to automatic review settings October 9, 2026 10:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The overflow-safe validation is correctly applied before allocation and is comprehensively tested across sync and async paths.

0 open findings

What changed in this PR

Adds pre-allocation bounds validation for 7z next headers, preventing truncated archives from triggering excessive allocations.

Changes:

  • Validates next-header ranges in synchronous and asynchronous readers.
  • Adds boundary and truncation tests for both paths.
File Description
ArchiveReader.cs Adds synchronous bounds validation.
ArchiveReader.Async.cs Adds equivalent asynchronous validation.
SevenZipHeaderValidationTests.cs Tests truncated and exact-boundary headers.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@adamhathcock
adamhathcock merged commit 9785f7d into release Oct 9, 2026
4 checks passed
@adamhathcock
adamhathcock deleted the fix/7z-next-header-bounds branch October 9, 2026 10:45
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.

2 participants