Skip to content

[TEST] ZipIfstream: cover the corrupt-archive error path (#9460) - #9535

Merged
timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:test/9460-zipifstream-corrupt
Jun 16, 2026
Merged

timosachsenberg merged 1 commit into
OpenMS:developfrom
timosachsenberg:test/9460-zipifstream-corrupt

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds a ZipIfstream_test section that writes garbage (non-ZIP) bytes to a *.zip temp file and asserts open() raises Exception::FileNotReadable — a clear exception rather than a crash or a garbage read.

Why

Closes part of the §1 (Qt removal: minizip-ng → libzip) [AUTO] task in the OpenMS 3.6.0 pre-release testing plan (#9460):

Add ZIP64-awareness + empty/corrupt-archive error-path cases. Pass: corrupt archive raises a clear exception; empty archive handled.

ZipIfstream_test already pins the empty (FileEmpty), multi-entry (ParseError) and nonexistent (FileNotFound) cases, but a corrupt archive was untested. On garbage input, libzip's zip_open() returns nullptr; since the file exists (not missing), ZipIfstream::open reports FileNotReadable (ZipIfstream.cpp:56) — this pins exactly that contract and distinguishes it from the missing-file FileNotFound path.

Scope note: the ZIP64 portion of that issue line needs a crafted ZIP64-format fixture (a >4 GB / >65535-entry archive), which isn't practical to synthesize SDK-free in a unit test, so it's left for a fixture-backed follow-up; empty is already covered; this PR closes the corrupt gap.

Test plan

Tests only — no production code changed. Verified locally: -fsyntax-only clean, full build green, test runs PASSED (the corrupt case raises FileNotReadable as expected; the temp file is created and removed by the test).

Part of #9460. Follows #9524, #9525, #9526, #9528, #9530, #9531, #9532, #9533, #9534.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for corrupt ZIP file handling, ensuring proper error handling when opening malformed ZIP files.

ZipIfstream_test already pinned the empty (FileEmpty), multi-entry (ParseError)
and nonexistent (FileNotFound) cases, but not a corrupt archive. Adds a section
that writes garbage (non-ZIP) bytes to a *.zip temp file and asserts open() raises
Exception::FileNotReadable -- a clear exception rather than a crash or garbage read
(libzip's zip_open returns nullptr and, since the file exists, ZipIfstream reports
it as not readable).

Verified: builds clean and the test runs PASSED.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

@timosachsenberg The following names might be missing from the AUTHORS file:

  • Timo Sachsenberg

Please consider applying the following patch:

--- AUTHORS	2026-06-15 16:27:02.527003695 +0000
+++ AUTHORS.new	2026-06-15 16:27:07.756578463 +0000
@@ -23,8 +23,8 @@
  - Chirag Dave
  - Chris Bauer
  - Chris Bielow
- - Christie Mathews
  - Christian Ehrlich
+ - Christie Mathews
  - Clemens Groepl
  - Cornelia Friedle
  - Daniel Jameson

@coderabbitai

coderabbitai Bot commented Jun 15, 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 707b1636-f498-4cd4-9119-09a4454c51e0

📥 Commits

Reviewing files that changed from the base of the PR and between aacd941 and 62c3fbb.

📒 Files selected for processing (1)
  • src/tests/class_tests/openms/source/ZipIfstream_test.cpp

📝 Walkthrough

Walkthrough

A new [EXTRA] unit test section is added to ZipIfstream_test.cpp. It includes OpenMS/SYSTEM/File.h, creates a temporary file with a .zip extension containing non-ZIP bytes, asserts that ZipIfstream::open throws Exception::FileNotReadable, and removes the temporary file.

Changes

ZipIfstream corrupt ZIP error handling test

Layer / File(s) Summary
Corrupt ZIP open exception test
src/tests/class_tests/openms/source/ZipIfstream_test.cpp
Adds OpenMS/SYSTEM/File.h include and an [EXTRA] test case that writes garbage bytes to a temp .zip file, verifies ZipIfstream::open throws Exception::FileNotReadable, and cleans up the temp file.

Possibly related PRs

  • OpenMS/OpenMS#9139: The new corrupt-ZIP error test directly exercises the ZipIfstream::open behavior introduced by the ZIP streaming/decompression work in this PR.
  • OpenMS/OpenMS#9345: The new test asserts the Exception::FileNotReadable contract tightened in ZipIfstream.h in this PR.

Poem

🐇 Hoppity-hop through the zip and the zap,
A file full of nonsense falls into a trap.
The stream tries to open—oh no, what a mess!
FileNotReadable thrown, I must confess.
Clean up the temp file, the test hops away,
A corrupt little zip can't ruin my day! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a test case for the corrupt-archive error path in ZipIfstream, which directly aligns with the changeset that introduces new test logic for handling corrupted ZIP files.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

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