Skip to content

[FIX] BrukerTimsFile: read zipped .d directories (.d.zip) in every caller - #10273

Merged
timosachsenberg merged 5 commits into
developfrom
claude/confident-lovelace-muuw2w-bruker-dzip
Sep 26, 2026
Merged

timosachsenberg merged 5 commits into
developfrom
claude/confident-lovelace-muuw2w-bruker-dzip

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

FileConverter -in DDA_HeLa_50ng_5_6min.d.zip -out x.mzML fails in the 3.6.0 nightly with "File not readable (... .d.zip (opentims: Not a directory))". pyOpenMS BrukerTimsFile().load() fails the same way on the archive. Yet the CHANGELOG announces transparent .zip input for Bruker .d directories (#9139). The 3.6.0 release-readiness check found this (C5).

Cause.

  • Add transparent .zip decompression for XML formats and Bruker .d #9139 unpacks a .d.zip only inside FileHandler::loadExperiment().
  • FileHandler::getType() reports the archive as BRUKER_TDF.
  • Every caller that needs BrukerTimsFile::Config calls BrukerTimsFile directly and bypasses FileHandler: FileConverter, PeakPickerIM, CometAdapter, ProteomicsLFQ, SwathFile (OpenSwathWorkflow) and the pyOpenMS binding. They hand the archive path straight to opentims, which only opens directories.
  • No test loads a .d.zip. The .d.zip item of the 3.6.0 testing plan Release testing #9460 was never ticked.

Fix.

  • The unpacking moves from FileHandler into BrukerTimsFile, the component that hands the path to opentims.
  • load(), transform(), readDIAMetadata() and loadDIAStreaming() unpack a .d.zip into a TempDir. They then read the .d directory inside, which may be nested:
    • They take the shallowest .d that holds analysis.tdf or analysis.tdf_bin, as FileHandler::getType() requires of a directory. Among equals, they take the first by name.
    • __MACOSX folders, which macOS's "Compress" adds, are skipped. Before, the first .d the directory iterator returned was taken, and for some run names that was __MACOSX/<name>.d.
    • An archive without such a .d is a ParseError: "ZIP archive does not contain a .d directory with analysis.tdf".
  • readDIAMetadata() keeps its extraction for the next call on the same object. SwathFile (OpenSwathWorkflow) sizes its consumer from the metadata and then calls loadDIAStreaming(). That call now reads the same files instead of unpacking the archive a second time. Any call other than readDIAMetadata() removes the kept files, as does destroying the object.
  • The source-file metadata still names the archive the user gave.
  • FileHandler now delegates, so there is one implementation.
  • This PR makes ZipArchiveFile::unzipDirectory() reachable from every BrukerTimsFile caller, so it now limits what an archive may write:
    • Before writing anything, it rejects an archive with more than 100,000 entries.
    • It also rejects one whose declared uncompressed size is more than 90% of the free space in the temporary directory. Extraction thus leaves room for the output and for other work on the same filesystem.
    • It stops any entry that inflates beyond its declared size.
    • It compares an entry's path with the target directory by path element, not as a string prefix. Before, ../parquet_unpacked_x/f was extracted next to the target directory, though still inside the per-call TempDir.

Validation

  • BrukerTimsFile_test gains three data-free sections:
    • One zips a directory without a .d (expects ParseError) and one with a nested run.d (which must reach opentims). Both checks fail on the installed nightly library and pass with the fix.
    • One zips run.d beside its __MACOSX twin and a deeper backup/old.d. load() must reach opentims through run.d. An archive with only __MACOSX/run.d and a .d without analysis.tdf must be a ParseError. Both checks fail on d01ebca and pass now; the second fails there whatever the directory order.
    • The last deletes the archive after readDIAMetadata(). loadDIAStreaming() must still reach opentims through the kept files, and a following load() must find nothing kept. This fails with per-call unpacking (this PR's first commit) and passes now.
  • ZipArchiveFile_test:
    • A stored 1 MiB entry whose headers declare 1000 bytes must be stopped. The nightly library extracts it in full without an error.
    • An entry ../parquet_unpacked_x/f.txt must be rejected. d01ebca extracts it.
  • The changed library files were rebuilt against the installed nightly libraries (8b25c6e) and their bundled libzip 1.11.4, the version vcpkg builds. With them:
    • A rebuilt FileConverter converts the 361 MB DDA_HeLa_50ng_5_6min.d.zip to 11,172 spectra (MS2 only, to keep the output small). The output is identical to converting the unzipped .d, apart from the source-file name and the index offsets that the name shifts. The temporary copy is removed afterwards. At ffc79f6 the output is still the same as at d01ebca, apart from the output name and the offsets it shifts.
    • Three crafted archives: a deflated 256 MiB entry declared as 1000 bytes, a ZIP64 entry declaring 1 PiB, and 100,001 empty entries. The nightly extracts all three. With the fix, each is rejected before any of its data is written.
    • Two ZIP64 archives declaring 95% and 80% of the free space in /tmp. The first is rejected, and the second extracts. d01ebca extracted both.
    • Seven macOS-style archives (<name>.d beside __MACOSX/<name>.d) on ext4: d01ebca handed __MACOSX/<name>.d to opentims for three of the names. 0e82250 reaches the real <name>.d for all seven.
  • Not checked:
    • pyOpenMS with the fix, because the wheel carries its own copy of the library. It calls the same loader.
    • A real DIA-PASEF archive, because none is at hand. CI never defines OPENTIMS_DIA_TEST_DATA, so the data-free section above is what covers the kept extraction.
  • No full local build or ctest; CI covers them.

Notes

  • Archives whose .d contents sit at the top level, rather than in a .d folder, are still rejected, as before.

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes (the changed test files were checked against rebuilt objects only; CI runs the suite)
  • Updated or added python bindings for changed or new classes (no binding change needed)

🤖 Generated with Claude Code

https://claude.ai/code/session_01YC1T2K9HQEUk2kQMZqC8h7


Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • Bruker TDF .d.zip archives can be used when loading data, reading DIA metadata, streaming DIA data, and transforming files. Nested archives select the shallowest valid data directory, and extracted files can be reused for a subsequent read of the same archive.
  • Bug Fixes
    • Archive extraction limits entry counts and checks declared sizes against available temporary storage. It also rejects oversized or malformed entries and prevents paths from escaping the extraction directory.
  • Documentation
    • Clarified ZIP support and how valid data directories are selected when unpacking Bruker TDF archives.

…ller

'FileConverter -in DDA_HeLa_50ng_5_6min.d.zip -out x.mzML' failed with
"File not readable (... .d.zip (opentims: Not a directory))", and so did
pyOpenMS BrukerTimsFile().load() on the archive, although the CHANGELOG
announces transparent .zip input for Bruker .d directories (#9139).

#9139 unpacked a .d.zip only inside FileHandler::loadExperiment(). Its
getType() reports the archive as BRUKER_TDF, and every caller that needs
BrukerTimsFile::Config calls BrukerTimsFile directly instead of going
through FileHandler: FileConverter, PeakPickerIM, CometAdapter,
ProteomicsLFQ, SwathFile (OpenSwathWorkflow) and the pyOpenMS binding.
They passed the archive path straight to opentims, which only opens
directories. #9139 verified .d.zip loading through FileHandler only, and
no test loads a .d.zip at all (the "[DATA] .d.zip load" item of the
3.6.0 testing plan #9460 was never done).

The unpacking moves from FileHandler into BrukerTimsFile, the component
that hands the path to opentims: load(), transform(), readDIAMetadata()
and loadDIAStreaming() unpack a .d.zip into a TempDir that lives for the
call and read the (possibly nested) .d directory inside, with the same
lookup and "ZIP archive does not contain a .d directory" error as
before. The source file metadata keeps naming the archive the user gave,
not the temporary directory. FileHandler now delegates, so there is one
implementation instead of a second one in each tool.

Test: an SDK- and data-free BrukerTimsFile_test section zips a directory
without a .d (ParseError) and one with a nested run.d (which must reach
opentims). Both checks fail before this change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YC1T2K9HQEUk2kQMZqC8h7
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: 23d7907b-07fe-4fcd-ac13-05a5a618abcc

📥 Commits

Reviewing files that changed from the base of the PR and between 0e82250 and ffc79f6.

📒 Files selected for processing (2)
  • src/openms/include/OpenMS/FORMAT/ZipArchiveFile.h
  • src/openms/source/FORMAT/ZipArchiveFile.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openms/include/OpenMS/FORMAT/ZipArchiveFile.h

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


📝 Walkthrough

Walkthrough

BrukerTimsFile now extracts zipped Bruker TDF inputs, selects a qualifying nested .d directory, and retains matching extractions for subsequent calls. FileHandler passes the original path to BrukerTimsFile. ZIP extraction now checks entry counts, sizes, available space, and path containment.

Changes

Bruker TDF archive loading

Layer / File(s) Summary
Validate ZIP extraction limits and paths
src/openms/include/OpenMS/FORMAT/ZipArchiveFile.h, src/openms/source/FORMAT/ZipArchiveFile.cpp, src/tests/class_tests/openms/source/ZipArchiveFile_test.cpp
unzipDirectory enforces entry-count and size limits, checks available temporary-directory space, and rejects paths outside the target directory. Tests cover oversized entries and path traversal.
Resolve and load zipped TDF paths
src/openms/include/OpenMS/FORMAT/BrukerTimsFile.h, src/openms/source/FORMAT/BrukerTimsFile.cpp, src/openms/source/FORMAT/FileHandler.cpp, src/openms/source/FORMAT/FileTypes.cpp, src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp, CHANGELOG
BrukerTimsFile selects the shallowest qualifying .d directory and skips __MACOSX. FileHandler passes the original input path. Tests cover archive selection, and comments and the changelog identify BrukerTimsFile as the unpacking component.
Retain extraction across matching calls
src/openms/include/OpenMS/FORMAT/BrukerTimsFile.h, src/openms/source/FORMAT/BrukerTimsFile.cpp, src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp
readDIAMetadata() retains the extraction for a subsequent matching call. loadDIAStreaming(), load(), and transform() use matching retained paths.

Sequence Diagram(s)

sequenceDiagram
  participant FileHandler
  participant BrukerTimsFile
  participant ZipArchiveFile
  participant opentims
  FileHandler->>BrukerTimsFile: Pass original Bruker TDF path
  BrukerTimsFile->>ZipArchiveFile: Extract ZIP archive
  ZipArchiveFile-->>BrukerTimsFile: Return extraction directory
  BrukerTimsFile->>BrukerTimsFile: Select qualifying .d directory
  BrukerTimsFile->>opentims: Open resolved .d path
Loading

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to ffc79

No concrete merge-blocking issue remains established for this change.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to ffc79

More Bruker loading paths can now process ZIP inputs. Extraction has stronger path and size checks, but simultaneous loads can still compete for temporary disk space; the practical exposure depends on how these loaders are used.

Retained concerns

  • Medium · security · inferred: Newly supported direct archive-loading paths share a temporary filesystem, while each extraction independently budgets against a free-space snapshot. If callers process archives concurrently, individually accepted archives can collectively deplete that filesystem.
Security review details

Security Blast Radius

  • inferred — Where an integration accepts untrusted files, its direct BrukerTimsFile calls can now cause archive extraction and temporary-disk writes. The evidence does not establish a network entrypoint, tenant scope, or privilege change.

Security Findings and Attack Paths

  • inferred — If multiple untrusted archives are loaded concurrently onto one temporary filesystem, each extraction can pass its own free-space check before their combined writes consume the available capacity. Existing FileHandler extraction had no such reservation either; this PR adds a stricter per-call limit but extends archive support to direct Bruker callers.

Trust Boundaries and Controls

  • observed — Caller-supplied archive paths cross into filesystem extraction before opentims reads the selected directory. Extraction now enforces path-component containment and per-archive resource checks at the shared ZIP boundary rather than in individual Bruker callers.

Resilience and Maintainability Implications

  • observed — Temporary files are owned by the retained extraction object, and the normal metadata-to-streaming handoff keeps them alive until consumption. ZIP handles are explicitly closed on checked errors, but filesystem exceptions during extraction are not covered by that explicit cleanup.

Hardening Proposals

  • proposed — If concurrent untrusted ingestion is supported, enforce an aggregate temporary-disk budget or isolate extraction capacity per workload rather than relying solely on a free-space snapshot.
  • proposed — Reject a negative archive entry count before converting it to an allocation size, and use scoped archive-handle ownership for exception paths. The negative-count behavior was already problematic in the base extraction loop; a reproducible PR-specific worsening has not been established.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.52% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 8 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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: BrukerTimsFile now reads zipped .d directories for all callers.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 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

A rabbit checks the zip with care,
Finds the TDF tucked safely there.
The shallow folder comes in view,
Retained files await the next call too.
Paths stay bounded, sizes known,
Then off through clover fields I roam.

Comment @coderabbitai help to get the list of available commands.

… extraction

This addresses the two concerns CodeRabbit's security review raised on
this PR.

DIA. SwathFile (OpenSwathWorkflow) sizes its consumer from
readDIAMetadata() and then streams the spectra with loadDIAStreaming(),
on one BrukerTimsFile. Each call unpacked the .d.zip into its own
temporary directory. The archive was unpacked twice, and the metadata
and the spectra could come from different extractions.
readDIAMetadata() now keeps its extraction, and the next call on the
same object reads it if that call asks for the same archive. Any call
other than readDIAMetadata() removes the kept files, as does destroying
the object.

Extraction. ZipArchiveFile::unzipDirectory() had no limit on what an
archive can write, and this PR makes it reachable from every
BrukerTimsFile caller, not only FileHandler. Before writing anything, it
now rejects an archive with more than 100000 entries, or one whose
declared uncompressed size exceeds the free space of the temporary
directory. It also stops an entry that inflates beyond its declared
size. With libzip 1.11.4, the version vcpkg builds, the old code wrote a
256 MiB entry declared as 1000 bytes in full and reported success.

Tests. ZipArchiveFile_test extracts a stored entry whose headers
declare 1000 of its 1 MiB. BrukerTimsFile_test deletes the archive
after readDIAMetadata(). It then expects loadDIAStreaming() to read the
kept files, and load() after that to find nothing kept. Both sections
fail without this change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YC1T2K9HQEUk2kQMZqC8h7

Copy link
Copy Markdown
Contributor Author

@coderabbitai Both retained concerns hold up, and a0081d2 addresses them:

  • Unlimited extraction. The limit now sits at the shared boundary, ZipArchiveFile::unzipDirectory(), so every caller gets it: FileHandler, BrukerTimsFile and the OpenSwath bundle code. Before writing anything, it rejects an archive with more than 100,000 entries. It also rejects one whose declared uncompressed size is larger than the free space in the temporary directory. While copying, it stops any entry that inflates beyond its declared size. That check is essential: with libzip 1.11.4, the old code wrote a 256 MiB entry declared as 1000 bytes in full and reported success.
  • Two DIA extractions. readDIAMetadata() keeps its extraction. A following loadDIAStreaming() on the same object reads it when it asks for the same archive. So the consumer sized from the metadata receives spectra from the same files, and the archive is unpacked only once. Any call other than readDIAMetadata() removes the kept files, as does destroying the object.
  • Docstring coverage. OpenMS documents its API in the headers. The new declarations in BrukerTimsFile.h and the new limits in ZipArchiveFile.h are documented there. By the codebase's convention, .cpp definitions and test sections carry no docstrings.

ZipArchiveFile_test and BrukerTimsFile_test each gain a section that fails without the corresponding fix.


Generated by Claude Code

@coderabbitai

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
git log -1 --format='%h %s'
git show --stat --oneline a0081d29
fd -t f '^(ZipArchiveFile|BrukerTimsFile)(_test)?\.(cpp|h)$'

Length of output: 1266


🏁 Script executed:

#!/bin/bash
set -euo pipefail
for name in BrukerTimsFile.cpp ZipArchiveFile.cpp; do
  path=$(fd -t f "$name" | head -1)
  echo "=== outline $path ==="
  ast-grep outline "$path" --items all --match 'resolveTimsDirectory|readDIAMetadata|loadDIAStreaming|unzipDirectory|load|transform' || true
done
git show --format=fuller --no-ext-diff --unified=12 a0081d29 -- src/openms/include/OpenMS/FORMAT/BrukerTimsFile.h src/openms/include/OpenMS/FORMAT/ZipArchiveFile.h src/openms/source/FORMAT/BrukerTimsFile.cpp src/openms/source/FORMAT/ZipArchiveFile.cpp src/tests/class_tests/openms/source/BrukerTimsFile_test.cpp src/tests/class_tests/openms/source/ZipArchiveFile_test.cpp

Length of output: 30486


@timosachsenberg, I reviewed a0081d2. The DIA path now reuses the extraction for the same archive, and both test files contain new regression sections. The header documentation follows the convention you described.

One extraction-limit gap remains: if std::filesystem::space() sets space_error, ZipArchiveFile::unzipDirectory() skips the free-space check and continues extracting. Please reject the archive when the free-space query fails. That would make the stated limit apply on this error path too. I did not run the tests.


✏️ Learnings added
Learnt from: timosachsenberg
URL: https://github.com/OpenMS/OpenMS/pull/10273

Timestamp: 2026-09-25T13:07:41.151Z
Learning: In OpenMS, API documentation belongs in header declarations. By codebase convention, `.cpp` definitions and test sections do not require docstrings.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

You are interacting with an AI system.

If std::filesystem::space() failed, unzipDirectory() skipped the
free-space check and extracted anyway, so the stated limit did not hold
on that path (found by CodeRabbit). It now rejects the archive with the
error the query returned. The query asks about the directory that
unzipDirectory() has just created, so this should happen only in unusual
setups.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YC1T2K9HQEUk2kQMZqC8h7

Copy link
Copy Markdown
Contributor Author

@coderabbitai Agreed. Since d01ebca, unzipDirectory() rejects the archive when std::filesystem::space() fails, with the error the query returned, and the header documents it. The query asks about the directory that unzipDirectory() has just created, so this should only happen in unusual setups. ZipArchiveFile_test and BrukerTimsFile_test still pass against the rebuilt library, as do the crafted archives and the 361 MB .d.zip conversion (11,172 spectra).


Generated by Claude Code

@coderabbitai

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
git log -1 --format='%h %s'
git show --stat --oneline d01ebca5
path=$(fd -t f '^ZipArchiveFile\.cpp$' | head -1)
header=$(fd -t f '^ZipArchiveFile\.h$' | head -1)
echo "=== outline $path ==="
ast-grep outline "$path" --match 'unzipDirectory' || true
echo "=== commit diff ==="
git show --format= --no-ext-diff --unified=12 d01ebca5 -- "$path" "$header"
echo "=== current free-space check ==="
rg -n -C 14 'filesystem::space|space_error|available|unzipDirectory' "$path" | head -170

Length of output: 8061


@timosachsenberg, thanks for the update. I verified that commit d01ebca5 makes ZipArchiveFile::unzipDirectory() reject the archive when std::filesystem::space() returns an error. The exception includes the query error. The header also documents this case. That addresses my remaining concern. I did not run the tests; the test and conversion results are your reported results.


✏️ Learnings added
Learnt from: timosachsenberg
URL: https://github.com/OpenMS/OpenMS/pull/10273

Timestamp: 2026-09-25T13:25:15.251Z
Learning: In OpenMS, `ZipArchiveFile::unzipDirectory()` queries free space for its newly created temporary extraction directory. If `std::filesystem::space()` returns an error, it rejects the archive with `Exception::InvalidValue` and includes the query error in the message.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: timosachsenberg
URL: https://github.com/OpenMS/OpenMS/pull/10273

Timestamp: 2026-09-25T13:07:41.700Z
Learning: In OpenMS, API documentation belongs in header declarations. By codebase convention, `.cpp` definitions and test sections do not require docstrings.

If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

You are interacting with an AI system.

@timosachsenberg timosachsenberg left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed at d01ebca. One finding inline, plus two notes outside the diff:

  • Nit, pre-existing: ZipArchiveFile.cpp:181-189 checks for traversal with a plain string prefix. An entry ../parquet_unpacked_evil/x normalizes to <TempDir>/parquet_unpacked_evil/x and is accepted. I checked this with a standalone g++ replica of the check. The file still lands inside the per-call TempDir and is removed with it. Comparing against base_str + '/', or using lexically_relative, would close it.
  • Nit: FileTypes.cpp:293 still says "'.d.zip' is unpacked by FileHandler".
  • Checked and found sound: the cleanup of the kept extraction on every path, including exceptions, and the entry, size and free-space limits (fail-closed, per-entry overrun stopped before the write). Also the header offsets that the zip-bomb test patches, and the uses of path vs d_path in load(), transform(), readDIAMetadata() and loadDIAStreaming(). There is no concurrency risk from pyOpenMS: its bindings don't release the GIL.
  • Not verified: I did not build or run the changed library or its tests, and I have no .d.zip data. Windows handling of non-ASCII paths (entry.path().string()) is untested.

Generated by Claude Code

Unpacking a .d.zip took the first .d directory that
recursive_directory_iterator returned. That order is unspecified, and an
archive made with macOS's "Compress" also holds __MACOSX/<name>.d with
AppleDouble files only. On ext4, run.d.zip, A.d.zip and X1.d.zip in that
layout handed __MACOSX/<name>.d to opentims; sample.d.zip, B.d.zip and
run2.d.zip did not.

Now the shallowest .d that holds analysis.tdf or analysis.tdf_bin is
read, as FileHandler::getType() requires of a directory, and the first by
name among equals. __MACOSX is skipped. An archive without such a .d is
reported as a ParseError before opentims sees it.

Also from the review:
- ZipArchiveFile::unzipDirectory compared paths as string prefixes, so
  '../parquet_unpacked_x/f' was extracted next to the target directory.
  It now compares path elements (lexically_relative). Such a file stayed
  inside the per-call TempDir.
- FileTypes.cpp still said that FileHandler unpacks .d.zip.

Tests: a BrukerTimsFile section with a macOS-style archive and one
without analysis.tdf, and a ZipArchiveFile section for the sibling
entry. Both fail on the previous head and pass now. The two existing
.d.zip sections put a placeholder analysis.tdf into run.d, so they
still reach opentims.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YC1T2K9HQEUk2kQMZqC8h7
CodeRabbit's security review of #10273 kept one concern. The free-space
check let an archive declare, and write, all of the free space in the
temporary directory, so a crafted archive could fill a filesystem that
other work shares. unzipDirectory now rejects an archive whose declared
size is more than 90% of the free space. That also leaves room for the
output, which usually goes to the same filesystem.

Checked with ZIP64 archives that declare 95% and 80% of the free space
in /tmp. The first is now rejected (d01ebca extracted it), and the
second still extracts. The crafted bomb, 1 PiB and 100,001-entry
archives are rejected as before. The 361 MB DDA_HeLa_50ng_5_6min.d.zip
converts to the same mzML apart from the output name and the index
offsets it shifts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YC1T2K9HQEUk2kQMZqC8h7

Copy link
Copy Markdown
Contributor Author

@coderabbitai On your review of ffc79f6:

  • Concurrent extractions. You're right that each call budgets against its own snapshot of the free space, so archives unpacked at the same time can together exceed it. An aggregate budget inside OpenMS would coordinate only the threads of one process, not the separate processes of a parallel pipeline, which is where concurrent ingestion usually happens. Isolation has to come from the deployment: give each job its own temporary directory (OPENMS_TMPDIR, or temp_dir in OpenMS.ini) on a volume or quota sized for it. I'm leaving this out of the code.
  • Negative entry count. zip_get_num_entries() returns -1 only for a NULL archive. za is checked right after zip_open(), so the count can't be negative there.
  • Handle on exception paths. A std::filesystem exception during extraction, for example from create_directories(), skips zip_close(), as it did before this PR. The TempDir is still removed; only the read-only handle stays open until the process ends. I'm leaving that as it is in this PR.

Generated by Claude Code

@coderabbitai

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🤖 web_search executed:

libzip 1.11.4 zip_get_num_entries returns -1 on error what errors can occur with non-NULL zip archive zip_get_num_entries manual

Length of output: 6185


🏁 Script executed:

#!/bin/bash
set -euo pipefail
p=$(fd -t f '^ZipArchiveFile\.cpp$' | head -1)
echo "file=$p"
ast-grep outline "$p" --match 'unzipDirectory' || true
rg -n -C 35 'zip_get_num_entries|zip_open\(|zip_close\(|filesystem::space|create_directories' "$p" | head -280
rg -n -C 3 'OPENMS_TMPDIR|temp_dir' src/openms/source/SYSTEM src/openms/include/OpenMS/SYSTEM 2>/dev/null | head -100 || true

Length of output: 18407


🏁 Script executed:

#!/bin/bash
set -euo pipefail
for url in \
  https://raw.githubusercontent.com/nih-at/libzip/v1.11.4/lib/zip_get_num_entries.c \
  https://libzip.org/documentation/zip_get_num_entries.html; do
  echo "=== $url ==="
  curl -fsSL --max-time 15 "$url" | sed -n '1,130p' || true
done

Length of output: 6658


@timosachsenberg, you are right about the negative entry count. I checked the libzip 1.11.4 implementation. With the flags used here, zip_get_num_entries() returns -1 for a null archive. ZipArchiveFile::unzipDirectory() checks the archive immediately after zip_open(). I withdraw that concern. My earlier reply left it unresolved without checking the implementation; sorry.

I accept per-job temporary storage as the approach for concurrent extractions. OpenMS supports OPENMS_TMPDIR and temp_dir for selecting that storage. The exception-path handle leak remains possible, but it predates this PR. I will not press for a change here. Would you like me to open a follow-up issue for the handle cleanup?


✏️ Learnings added
Learnt from: timosachsenberg
URL: https://github.com/OpenMS/OpenMS/pull/10273

Timestamp: 2026-09-25T17:20:49.799Z
Learning: In OpenMS, `ZipArchiveFile::unzipDirectory()` checks that `zip_open()` returned a non-null archive before calling `zip_get_num_entries()`. In libzip 1.11.4, `zip_get_num_entries()` returns `-1` for a null archive; with flags 0 and a non-null archive, it returns the archive's entry count.

Learnt from: timosachsenberg
URL: https://github.com/OpenMS/OpenMS/pull/10273

Timestamp: 2026-09-25T17:20:49.799Z
Learning: For concurrent OpenMS ZIP extractions in separate pipeline processes, per-job temporary storage can be selected with `OPENMS_TMPDIR` or `temp_dir` in OpenMS.ini. An in-process aggregate extraction budget would not coordinate separate processes.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

You are interacting with an AI system.

@timosachsenberg

Copy link
Copy Markdown
Contributor Author

Streaming from zip would be great

Copy link
Copy Markdown
Contributor Author

Streaming would help, but this PR still unpacks the archive, for two reasons:

  • opentims opens analysis.tdf_bin from a file path. It memory-maps the file (mio::mmap_source) and reads each frame at its offset, and every TimsDataHandle constructor takes paths. SQLite also needs analysis.tdf as a file.
  • Random access into a deflated ZIP entry needs decompression. In our test archive DDA_HeLa_50ng_5_6min.d.zip, analysis.tdf_bin is deflated (366 MB → 358 MB; the frames are already zstd-compressed, so deflate saves only about 2%).

A follow-up could do this:

  1. Stored entries (zip -0): extract only analysis.tdf (12 MB here), map the ZIP file itself, and give opentims the byte range of analysis.tdf_bin. The bulk data would then need no copy at all. This needs an opentims constructor that takes a mapped buffer or a (path, offset, length). We fetch opentims from michalsta/opentims v1.2.0b4 and also accept a system installation, so this would be an upstream change rather than a local patch.
  2. Deflated entries: decompress analysis.tdf_bin into memory instead of the temp directory. That saves temp disk space but needs as much RAM as the file is large, so I would keep unpacking to disk as the default.

This PR fixes the 3.6.0 blocker (.d.zip input failing completely). Streaming, as in (1), could follow as a separate change.


Generated by Claude Code

@timosachsenberg
timosachsenberg merged commit 9a69786 into develop Sep 26, 2026
32 checks passed
@timosachsenberg
timosachsenberg deleted the claude/confident-lovelace-muuw2w-bruker-dzip branch September 26, 2026 10:53
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