Skip to content

zip_reader: clean up after hash setup failures on entry open - #1068

Merged
nmoinvaz merged 2 commits into
developfrom
fix/reader-hash-open-cleanup
Sep 17, 2026
Merged

nmoinvaz merged 2 commits into
developfrom
fix/reader-hash-open-cleanup

Conversation

@nmoinvaz

@nmoinvaz nmoinvaz commented Sep 17, 2026

Copy link
Copy Markdown
Member

Follow-up to #1047 for the remaining review threads on mz_zip_reader_entry_open.

When the hash object could not be allocated or the entry named an unsupported algorithm, the entry was left open and a half initialized hash object was kept. A retry of the open then returned MZ_OK and read the entry without verification. Every failure after the low-level open now drops the hash object and closes the entry.

A hash record could also declare a supported algorithm with any digest length up to MZ_HASH_MAX_SIZE. A zero length record made the compare on close trivially succeed. The length must now equal the algorithm's digest size, otherwise the open fails with MZ_FORMAT_ERROR.

Sources are the review threads on #1047, #1047 (comment) and #1047 (comment).

@coderabbitai

coderabbitai Bot commented Sep 17, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: eba7896f-2b4c-4625-a4e9-416576c1c543

📥 Commits

Reviewing files that changed from the base of the PR and between d05f2e4 and 66ae211.

📒 Files selected for processing (2)
  • mz_zip_rw.c
  • test/test_reader.cc

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


Walkthrough

The reader now validates hash algorithm and digest-size metadata before creating a hash context. Hash setup failures use shared cleanup. Reader tests cover oversized, unsupported, and mismatched digest metadata, including repeated entry-open attempts.

Changes

Hash validation

Layer / File(s) Summary
Hash setup validation and cleanup
mz_zip_rw.c
mz_zip_reader_entry_open derives the expected digest size, rejects unsupported algorithms and mismatched digest sizes, creates the configured hash context, and uses shared cleanup for failures.
Invalid hash metadata tests
test/test_reader.cc
Shared in-memory reader helpers support tests for oversized SHA-1 digests, unsupported MD5 algorithms, and zero-length SHA-1 digests. Each test repeats mz_zip_reader_entry_open and checks the expected error.

Suggested reviewers: canbolayir

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 66ae2

The hash metadata validation and retry cleanup changes are ready to merge based on the available evidence.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly summarizes the main change: cleanup after hash setup failures during entry open.
Description check ✅ Passed The description directly explains the hash cleanup, retry behavior, digest-length validation, and regression tests.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

When the hash object cannot be allocated or the entry names an
algorithm the backend does not support, the entry was left open and
a partially initialized hash object was kept. A retry of the open
then returned success and read the entry without verification.

Route every failure after the low-level open through one cleanup
that drops the hash object and closes the entry.

Assisted-By: Claude <noreply@anthropic.com>
A hash extra field could declare a supported algorithm with any digest
length up to the buffer size. A zero length record made the comparison
on close trivially succeed, and a longer one compared uninitialized
bytes. Reject any length other than the algorithm's digest size before
the hash object is created.

Assisted-By: Claude <noreply@anthropic.com>
@nmoinvaz
nmoinvaz force-pushed the fix/reader-hash-open-cleanup branch from 66ae211 to 67169fc Compare September 17, 2026 19:26
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (d05f2e4) to head (66ae211).

⚠️ Current head 66ae211 differs from pull request most recent head 67169fc

Please upload reports for the commit 67169fc to get more accurate results.

Additional details and impacted files
@@       Coverage Diff       @@
##   develop   #1068   +/-   ##
===============================
===============================

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nmoinvaz nmoinvaz added the cleanup Housekeeping tasks label Sep 17, 2026
@nmoinvaz
nmoinvaz merged commit 1248b46 into develop Sep 17, 2026
64 checks passed
@nmoinvaz
nmoinvaz deleted the fix/reader-hash-open-cleanup branch September 17, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup Housekeeping tasks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant