Repository navigation
[FIX] BrukerTimsFile: read zipped .d directories (.d.zip) in every caller - #10273
Conversation
…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
|
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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 4 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthrough
ChangesBruker TDF archive loading
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
Priority: ➖ Normal Change: Bug fix Merge Risk: ⚪ Minimal · up to No concrete merge-blocking issue remains established for this change. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to 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
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. A rabbit checks the zip with care, Comment |
… 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
|
@coderabbitai Both retained concerns hold up, and a0081d2 addresses them:
Generated by Claude Code |
|
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.cppLength of output: 30486
One extraction-limit gap remains: if ✏️ Learnings added
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
|
@coderabbitai Agreed. Since d01ebca, Generated by Claude Code |
|
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 -170Length of output: 8061
✏️ Learnings added
🧠 Learnings usedIf 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
left a comment
There was a problem hiding this comment.
Reviewed at d01ebca. One finding inline, plus two notes outside the diff:
- Nit, pre-existing:
ZipArchiveFile.cpp:181-189checks for traversal with a plain string prefix. An entry../parquet_unpacked_evil/xnormalizes to<TempDir>/parquet_unpacked_evil/xand 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 againstbase_str + '/', or usinglexically_relative, would close it. - Nit:
FileTypes.cpp:293still 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
pathvsd_pathinload(),transform(),readDIAMetadata()andloadDIAStreaming(). 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.zipdata. 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
|
@coderabbitai On your review of ffc79f6:
Generated by Claude Code |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🤖 web_search executed:
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 || trueLength 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
doneLength of output: 6658
I accept per-job temporary storage as the approach for concurrent extractions. OpenMS supports ✏️ Learnings added
You are interacting with an AI system. |
|
Streaming from zip would be great |
|
Streaming would help, but this PR still unpacks the archive, for two reasons:
A follow-up could do this:
This PR fixes the 3.6.0 blocker ( Generated by Claude Code |
Description
FileConverter -in DDA_HeLa_50ng_5_6min.d.zip -out x.mzMLfails in the 3.6.0 nightly with "File not readable (... .d.zip (opentims: Not a directory))". pyOpenMSBrukerTimsFile().load()fails the same way on the archive. Yet the CHANGELOG announces transparent.zipinput for Bruker.ddirectories (#9139). The 3.6.0 release-readiness check found this (C5).Cause.
.d.ziponly insideFileHandler::loadExperiment().FileHandler::getType()reports the archive asBRUKER_TDF.BrukerTimsFile::ConfigcallsBrukerTimsFiledirectly 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..d.zip. The.d.zipitem of the 3.6.0 testing plan Release testing #9460 was never ticked.Fix.
BrukerTimsFile, the component that hands the path to opentims.load(),transform(),readDIAMetadata()andloadDIAStreaming()unpack a.d.zipinto aTempDir. They then read the.ddirectory inside, which may be nested:.dthat holdsanalysis.tdforanalysis.tdf_bin, asFileHandler::getType()requires of a directory. Among equals, they take the first by name.__MACOSXfolders, which macOS's "Compress" adds, are skipped. Before, the first.dthe directory iterator returned was taken, and for some run names that was__MACOSX/<name>.d..dis aParseError: "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 callsloadDIAStreaming(). That call now reads the same files instead of unpacking the archive a second time. Any call other thanreadDIAMetadata()removes the kept files, as does destroying the object.ZipArchiveFile::unzipDirectory()reachable from everyBrukerTimsFilecaller, so it now limits what an archive may write:../parquet_unpacked_x/fwas extracted next to the target directory, though still inside the per-callTempDir.Validation
BrukerTimsFile_testgains three data-free sections:.d(expectsParseError) and one with a nestedrun.d(which must reach opentims). Both checks fail on the installed nightly library and pass with the fix.run.dbeside its__MACOSXtwin and a deeperbackup/old.d.load()must reach opentims throughrun.d. An archive with only__MACOSX/run.dand a.dwithoutanalysis.tdfmust be aParseError. Both checks fail on d01ebca and pass now; the second fails there whatever the directory order.readDIAMetadata().loadDIAStreaming()must still reach opentims through the kept files, and a followingload()must find nothing kept. This fails with per-call unpacking (this PR's first commit) and passes now.ZipArchiveFile_test:../parquet_unpacked_x/f.txtmust be rejected. d01ebca extracts it.8b25c6e) and their bundled libzip 1.11.4, the version vcpkg builds. With them:DDA_HeLa_50ng_5_6min.d.zipto 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./tmp. The first is rejected, and the second extracts. d01ebca extracted both.<name>.dbeside__MACOSX/<name>.d) on ext4: d01ebca handed__MACOSX/<name>.dto opentims for three of the names. 0e82250 reaches the real<name>.dfor all seven.OPENTIMS_DIA_TEST_DATA, so the data-free section above is what covers the kept extraction.Notes
.dcontents sit at the top level, rather than in a.dfolder, are still rejected, as before.Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01YC1T2K9HQEUk2kQMZqC8h7
Generated by Claude Code
Summary by CodeRabbit
.d.ziparchives 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.