Skip to content

feat: add index_for_name_raw - #1210

Merged
Pr0methean merged 7 commits into
masterfrom
add-index
Oct 30, 2026
Merged

Pr0methean merged 7 commits into
masterfrom
add-index

Conversation

@Its-Just-Nans

@Its-Just-Nans Its-Just-Nans commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #1208.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@amazon-q-developer amazon-q-developer Bot 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.

This PR adds index_for_name_raw(&self, name: &[u8]) -> Option<usize> to ZipArchive, providing a direct O(1) raw-byte lookup without the CP437 fallback of index_for_name. The implementation is correct — it delegates directly to IndexMap::get_index_of. The doc-link fix in src/result.rs (correcting ExtractOptions::size_limit → ExtractOptions::with_size_limit) is also correct.

One issue found: a typo ("considiser") in the new doc comment on index_for_name. A one-click fix has been suggested.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

Comment thread src/read/zip_archive.rs Resolved
@Its-Just-Nans

Its-Just-Nans commented Oct 28, 2026 •

Copy link
Copy Markdown
Member Author

Should fix #1208

@Goldziher ping - you might be interested by this change

@ouyangjiahong26

Copy link
Copy Markdown
Contributor

The new API matches the request in #1208, and its semantics check out against the CP437 fixture from #1080: index_for_name_raw(b"cafe\x82.txt") returns the entry, index_for_name_raw("café.txt".as_bytes()) returns None, and index_for_name("café.txt") still returns Some.

Before merge, consider:

  • adding regression tests for index_for_name_raw (raw hit usable with by_index; decoded CP437 name miss; non-UTF-8 raw bytes; raw match precedence over a decoded collision);
  • documenting that the method performs no decoding or fallback and stating its average O(1) lookup cost, as Expose an exact raw-name lookup API to avoid repeated full-archive scans during candidate lookup #1208 requests;
  • adding a closing reference (Fixes #1208) so the issue closes on merge — the current "Should fix " comment does not auto-close it;
  • rerunning fuzz_write_with_no_features: it reports one write-fuzz crash, which looks unrelated to this read-side change.

@Goldziher

Copy link
Copy Markdown
Contributor

nice

@Pr0methean

Copy link
Copy Markdown
Member

@ouyangjiahong26 Thanks for your review; I made the requested changes.

Its-Just-Nans and others added 7 commits October 28, 2026 18:23
Co-authored-by: amazon-q-developer[bot] <208079219+amazon-q-developer[bot]@users.noreply.github.com>
Signed-off-by: n4n5 <git@n4n5.dev>
Signed-off-by: Chris Hennick <4961925+Pr0methean@users.noreply.github.com>
@Pr0methean
Pr0methean disabled auto-merge October 29, 2026 02:13
@Pr0methean
Pr0methean added this pull request to the merge queue Oct 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 29, 2026
@Pr0methean

Copy link
Copy Markdown
Member

@cycle-five Could you please take a look at this fuzz failure? https://github.com/zip-rs/zip2/actions/runs/40805120389/artifacts/12869415245

@cycle-five

Copy link
Copy Markdown
Contributor

Reproduced with fuzz/replay.sh on the crash artifact; it fails identically on master 9926c64, so it's not caused by this PR.

Root cause is in the harness: FuzzTestCase::execute only updates comment_len_at_reopen when the top-level op reopens. Here a 6-byte comment is followed by a copy chain whose bases reopen (ViaFinishIntoReadable/ViaFinish), then a 1-byte comment. The shrink pads junk before the first local header, but streamable stays true, so read_zipfile_from_stream → Invalid local file header is reported as a failure. The library behaves as expected; ZipArchive::new reads the result fine.

Fix: look through ShallowCopy/DeepCopy bases when deciding whether an op reopens the writer (not merge sub-writers, which have their own writer). Adds the input as fuzz/write/regressions/nested-copy-comment-shrink-junk.bin. All 1011 inputs in in + regressions replay clean. I will open a separate fix(fuzz): ... PR against master.

Merged via the queue into master with commit 5138b4c Oct 30, 2026
135 checks passed
@Pr0methean
Pr0methean deleted the add-index branch October 30, 2026 17:31
stevehill1981 added a commit to cat198x/cat198x that referenced this pull request Nov 7, 2026
zip 9.2.0 (zip-rs/zip2#1210) gave `index_for_name` a fallback that
matches an entry by its decoded name, so `by_name("å.bin")` now finds the
CP437-named fixture. The test asserted that the lookup still failed, which
pinned an upstream bug rather than our behaviour.

Keep the checks that guard cat198x: `resolve_zip_entry_index` finds the
entry and extraction by decoded name returns its bytes. The CP437 name
identity test still passes unchanged on zip 9.2.2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose an exact raw-name lookup API to avoid repeated full-archive scans during candidate lookup

5 participants