Skip to content

fix: Reset CRC context state on source reopen - #575

Open
XananasX7 wants to merge 1 commit into
nih-at:mainfrom
XananasX7:fix/crc-state-reset-on-reopen
Open

fix: Reset CRC context state on source reopen#575
XananasX7 wants to merge 1 commit into
nih-at:mainfrom
XananasX7:fix/crc-state-reset-on-reopen

Conversation

@XananasX7

Copy link
Copy Markdown
Contributor

Summary

When a CRC source is reopened (ZIP_SOURCE_OPEN), only position was reset to zero. The remaining context fields — crc_position, crc, crc_complete, and size — retained stale values from the previous read pass.

Problem

On a second open/read/close cycle, this could cause:

  • CRC validation to be skipped (if crc_complete was still set from the prior pass)
  • Incorrect size and CRC reported via ZIP_SOURCE_STAT
  • Stale accumulated CRC used for validation of new data

This is the same class of bug as the WinZip AES HMAC state reset (commit e1f2793). That fix correctly reset hmac_verified on reopen, but the CRC source was not given the same treatment.

Fix

Reset all CRC context fields on reopen to match the initial-state semantics expected by the layered source protocol.

Testing

  • Builds cleanly with ASAN/UBSAN (gcc 13, Ubuntu 24.04)
  • The existing test suite passes

When a CRC source is reopened (ZIP_SOURCE_OPEN), only `position` was
reset to zero.  The remaining context fields -- `crc_position`, `crc`,
`crc_complete`, and `size` -- retained stale values from the previous
read pass.  On a second open/read/close cycle, this could cause:

 - CRC validation to be skipped (if `crc_complete` was still set from
   the prior pass)
 - Incorrect size and CRC reported via ZIP_SOURCE_STAT
 - Stale accumulated CRC used for validation of new data

This is the same class of bug as the WinZip AES HMAC state reset
(commit e1f2793).  Reset all CRC context fields on reopen to match
the initial-state semantics expected by the layered source protocol.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
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