Repository navigation
Use libzip instead of minizip-ng for ZIP64 archive support - #8808
Conversation
Includes Arrow upgrade from 22.0.0 to 23.0.0 and various build fixes. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Integrate minizip-ng v4.0.7 across all build paths: - contrib: build script and archive metadata (source uploaded to contrib-sources) - vcpkg: add minizip-ng to dependencies - CMake: dual-name find_package fallback (minizip-ng / minizip) for vcpkg/contrib (-ng suffix) and conda-forge (no suffix) compatibility - CI: brew install (macOS), build from source (Ubuntu), conda install (Windows) Closes #8791 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Use libzip instead of minizip-ng: simpler CMake integration (single find_package vs dual-name fallback), available via apt on Ubuntu 24.04 (no build-from-source needed), and equivalent functionality for STORE entry random access via zip_fseek/zip_fread/zip_ftell. Co-Authored-By: Claude Opus 4.6 <[email protected]>
The contrib bump in the base branch added a minizip-ng build script. Replace it with a libzip 1.11.4 build script instead, matching the switch from minizip-ng to libzip in the main OpenMS build. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds libzip as a required dependency across CI, packaging, and CMake; links libzip into OpenMS and tests; introduces a ZipEntryRandomAccessFile adapter and tests for ZIP random-access and optional Parquet round-trips. Changes
Sequence DiagramsequenceDiagram
participant Test as Test Suite
participant Libzip as libzip (zip_t / zip_file_t)
participant Disk as Filesystem
participant Arrow as Arrow/Parquet
Test->>Libzip: create ZIP, add STORE entries
Libzip->>Disk: write ZIP file
Test->>Libzip: open ZIP, locate entry
Test->>Test: construct ZipEntryRandomAccessFile(adapter)
Test->>Arrow: request read via RandomAccessFile API
Arrow->>Test: return table/bytes
Test->>Test: validate contents & schema
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/tests/class_tests/openms/source/Libzip_test.cpp`:
- Around line 62-71: The Tell/Seek/Read methods must guard against
use-after-close by checking closed_ or entry_ before dereferencing entry_;
update Tell, Seek, and Read (and any similar methods that access entry_) to
first return an appropriate arrow::Status (e.g., Status::IOError or
Status::Invalid) if closed_ is true or entry_ == nullptr, and only perform
zip_fd operations when entry_ is non-null; this prevents crashes after Close()
sets entry_ and archive_ to nullptr.
- Around line 177-183: The test shares a single zip_path across START_SECTION
blocks causing cross-section coupling; make the ZIP creation local to each
section by declaring a local std::string zip_path (or renaming to
zip_path_<section>) and calling NEW_TMP_FILE(zip_path) inside every
START_SECTION that needs an archive (including the sections currently reusing
the shared variable), then append ".zip" and build the archive there—remove the
file-scoped zip_path so each section creates and owns its own temporary output
file (ensure references to zip_path in functions like the archive
creation/assertion calls are updated to use the local variable).
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
.github/workflows/openms_ci_matrix_full.ymlcmake/cmake_findExternalLibs.cmakecontribsrc/openms/CMakeLists.txtsrc/tests/class_tests/openms/CMakeLists.txtsrc/tests/class_tests/openms/executables.cmakesrc/tests/class_tests/openms/source/Libzip_test.cpptools/ci/deps-macos.shtools/ci/deps-ubuntu.shvcpkg.json
| arrow::Status Close() override | ||
| { | ||
| if (!closed_) | ||
| { | ||
| if (entry_) { zip_fclose(entry_); entry_ = nullptr; } | ||
| if (archive_) { zip_close(archive_); archive_ = nullptr; } | ||
| closed_ = true; | ||
| } | ||
| return arrow::Status::OK(); | ||
| } |
There was a problem hiding this comment.
Guard Tell/Seek/Read against use-after-close.
After Line 66 and Line 67 set handles to nullptr, Line 77, Line 88, and Line 95 still dereference entry_ unconditionally. A call after Close() can crash instead of returning an error status.
🛠️ Proposed fix
class ZipEntryRandomAccessFile : public arrow::io::RandomAccessFile
{
public:
+ arrow::Status ensureOpen() const
+ {
+ if (closed_ || entry_ == nullptr)
+ {
+ return arrow::Status::Invalid("ZIP entry is closed");
+ }
+ return arrow::Status::OK();
+ }
+
arrow::Result<int64_t> Tell() const override
{
+ ARROW_RETURN_NOT_OK(ensureOpen());
zip_int64_t pos = zip_ftell(entry_);
if (pos < 0) return arrow::Status::IOError("zip_ftell failed");
return static_cast<int64_t>(pos);
}
@@
arrow::Status Seek(int64_t position) override
{
+ ARROW_RETURN_NOT_OK(ensureOpen());
if (position < 0 || position > entry_size_)
return arrow::Status::IOError("Seek out of bounds");
@@
arrow::Result<int64_t> Read(int64_t nbytes, void* out) override
{
+ ARROW_RETURN_NOT_OK(ensureOpen());
zip_int64_t bytes_read = zip_fread(entry_, out, static_cast<zip_uint64_t>(nbytes));
if (bytes_read < 0) return arrow::Status::IOError("zip_fread failed");
return static_cast<int64_t>(bytes_read);
}Also applies to: 75-98
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/tests/class_tests/openms/source/Libzip_test.cpp` around lines 62 - 71,
The Tell/Seek/Read methods must guard against use-after-close by checking
closed_ or entry_ before dereferencing entry_; update Tell, Seek, and Read (and
any similar methods that access entry_) to first return an appropriate
arrow::Status (e.g., Status::IOError or Status::Invalid) if closed_ is true or
entry_ == nullptr, and only perform zip_fd operations when entry_ is non-null;
this prevents crashes after Close() sets entry_ and archive_ to nullptr.
| std::string zip_path; | ||
|
|
||
| START_SECTION(create_uncompressed_zip_archive) | ||
| { | ||
| NEW_TMP_FILE(zip_path) | ||
| zip_path += ".zip"; | ||
|
|
There was a problem hiding this comment.
Avoid cross-section fixture sharing; build the ZIP in each section.
Line 177 introduces a shared zip_path, and later sections (e.g., Line 223, Line 290, Line 358) depend on state produced by a different START_SECTION. This creates ordering/side-effect coupling and cascading failures.
🧪 Suggested restructuring pattern
-std::string zip_path;
+auto createZipFixture = [&]() -> std::string
+{
+ std::string path;
+ NEW_TMP_FILE(path)
+ path += ".zip";
+ // create archive + add entries + zip_close(...)
+ return path;
+};
START_SECTION(random_access_by_filename)
{
+ const std::string zip_path = createZipFixture();
int err = 0;
zip_t* archive = zip_open(zip_path.c_str(), ZIP_RDONLY, &err);
TEST_NOT_EQUAL(archive, nullptr)
...
}Also applies to: 220-223, 289-291, 358-359
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/tests/class_tests/openms/source/Libzip_test.cpp` around lines 177 - 183,
The test shares a single zip_path across START_SECTION blocks causing
cross-section coupling; make the ZIP creation local to each section by declaring
a local std::string zip_path (or renaming to zip_path_<section>) and calling
NEW_TMP_FILE(zip_path) inside every START_SECTION that needs an archive
(including the sections currently reusing the shared variable), then append
".zip" and build the archive there—remove the file-scoped zip_path so each
section creates and owns its own temporary output file (ensure references to
zip_path in functions like the archive creation/assertion calls are updated to
use the local variable).
libzip <= 1.10 ships a CMake config that unconditionally imports CLI tool targets (zipcmp, zipmerge, ziptool). If the tools package is not installed (e.g. Ubuntu libzip-dev without libzip-tools), the config raises a FATAL_ERROR that QUIET cannot suppress. Add a FindLibzip.cmake module that does a manual header+library search, creating the libzip::zip imported target directly. This works on all platforms (apt, brew, conda, vcpkg, contrib) regardless of libzip version. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…move mutex - Fix inaccurate comment in cmake_findExternalLibs.cmake (we skip CONFIG mode entirely, not "try CONFIG first then fall back") - Add 'libzip' as alternative library name in FindLibzip.cmake for Windows - Add mark_as_advanced for LIBZIP_INCLUDE_DIR and LIBZIP_LIBRARY - Remove mutex from ZipEntryRandomAccessFile (each handle is single-threaded) - Update class documentation to note not-thread-safe contract Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
♻️ Duplicate comments (2)
src/tests/class_tests/openms/source/Libzip_test.cpp (2)
62-71:⚠️ Potential issue | 🟠 MajorGuard ZIP handle access after
Close()to prevent null dereference.After Line 66 and Line 67 set handles to
nullptr, Line 77, Line 88, and Line 95 still dereferenceentry_unconditionally. Calls afterClose()can crash instead of returning anarrow::Status.Suggested fix
class ZipEntryRandomAccessFile : public arrow::io::RandomAccessFile { public: + arrow::Status ensureOpen_() const + { + if (closed_ || entry_ == nullptr) + { + return arrow::Status::Invalid("ZIP entry is closed"); + } + return arrow::Status::OK(); + } + arrow::Result<int64_t> Tell() const override { + ARROW_RETURN_NOT_OK(ensureOpen_()); zip_int64_t pos = zip_ftell(entry_); if (pos < 0) return arrow::Status::IOError("zip_ftell failed"); return static_cast<int64_t>(pos); } @@ arrow::Status Seek(int64_t position) override { + ARROW_RETURN_NOT_OK(ensureOpen_()); if (position < 0 || position > entry_size_) return arrow::Status::IOError("Seek out of bounds"); @@ arrow::Result<int64_t> Read(int64_t nbytes, void* out) override { + ARROW_RETURN_NOT_OK(ensureOpen_()); zip_int64_t bytes_read = zip_fread(entry_, out, static_cast<zip_uint64_t>(nbytes)); if (bytes_read < 0) return arrow::Status::IOError("zip_fread failed"); return static_cast<int64_t>(bytes_read); }#!/bin/bash # Verify dereference sites and absence of a pre-check before libzip calls. rg -n -C2 'Close\(\)|Tell\(|Seek\(|Read\(int64_t nbytes, void\* out\)|zip_ftell|zip_fseek|zip_fread|closed_|entry_ == nullptr' src/tests/class_tests/openms/source/Libzip_test.cppAlso applies to: 75-98
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/tests/class_tests/openms/source/Libzip_test.cpp` around lines 62 - 71, The test harness dereferences zip handles after Close() because functions like Tell(), Seek(), and Read(int64_t nbytes, void* out) use entry_ and archive_ without checking closed_ or null; update each of these methods to first check closed_ (or that entry_ / archive_ != nullptr) and return an appropriate arrow::Status error if the stream is closed, then only call zip_ftell/zip_fseek/zip_fread when the handles are valid; reference Close(), Tell(), Seek(), Read(int64_t nbytes, void* out), and the members entry_, archive_, closed_ when making the guard changes.
174-179:⚠️ Potential issue | 🟠 MajorAvoid cross-section state coupling via shared
zip_path.
zip_pathis created in one section and consumed by later sections, which makes sections order-dependent and brittle. Build or prepare the ZIP fixture per section (or via a helper called in each section) and keep each section self-contained.Restructure pattern
-std::string zip_path; +auto createZipFixture = [&]() -> std::string +{ + std::string local_zip_path; + NEW_TMP_FILE(local_zip_path) + local_zip_path += ".zip"; + int err = 0; + zip_t* archive = zip_open(local_zip_path.c_str(), ZIP_CREATE | ZIP_TRUNCATE, &err); + TEST_NOT_EQUAL(archive, nullptr) + // add file1/file2/file3 with ZIP_CM_STORE... + TEST_EQUAL(zip_close(archive), 0) + return local_zip_path; +}; START_SECTION(random_access_by_filename) { + const std::string zip_path = createZipFixture(); int err = 0; zip_t* archive = zip_open(zip_path.c_str(), ZIP_RDONLY, &err);Based on learnings:
Use NEW_TMP_FILE(filename) for each temporary output file in tests to avoid side effects; do not reuse output files across test sections.Also applies to: 217-221, 281-288, 349-356
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/tests/class_tests/openms/source/Libzip_test.cpp` around lines 174 - 179, Currently a single shared variable zip_path is prepared once and reused across multiple START_SECTION blocks (e.g., create_uncompressed_zip_archive), creating order-dependent tests; make each test section self-contained by declaring and initializing its own local zip_path with NEW_TMP_FILE(...) inside the START_SECTION (or call a small helper that returns a fresh temp path) so no section relies on state set by a different section; update all sections that consume zip_path to use a locally-created temp file rather than the shared variable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/tests/class_tests/openms/source/Libzip_test.cpp`:
- Around line 62-71: The test harness dereferences zip handles after Close()
because functions like Tell(), Seek(), and Read(int64_t nbytes, void* out) use
entry_ and archive_ without checking closed_ or null; update each of these
methods to first check closed_ (or that entry_ / archive_ != nullptr) and return
an appropriate arrow::Status error if the stream is closed, then only call
zip_ftell/zip_fseek/zip_fread when the handles are valid; reference Close(),
Tell(), Seek(), Read(int64_t nbytes, void* out), and the members entry_,
archive_, closed_ when making the guard changes.
- Around line 174-179: Currently a single shared variable zip_path is prepared
once and reused across multiple START_SECTION blocks (e.g.,
create_uncompressed_zip_archive), creating order-dependent tests; make each test
section self-contained by declaring and initializing its own local zip_path with
NEW_TMP_FILE(...) inside the START_SECTION (or call a small helper that returns
a fresh temp path) so no section relies on state set by a different section;
update all sections that consume zip_path to use a locally-created temp file
rather than the shared variable.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
cmake/Modules/FindLibzip.cmakecmake/cmake_findExternalLibs.cmakesrc/tests/class_tests/openms/source/Libzip_test.cpp
Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
some custom cmake code was necessary (at least for the version that ships with ubuntu 24.04). They also recently split the target into several subtargets in recent versions etc. |
Tell, Seek, and Read now return arrow::Status::Invalid before dereferencing entry_ when the file has been closed. Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
src/tests/class_tests/openms/source/Libzip_test.cpp (1)
177-183:⚠️ Potential issue | 🟠 MajorAvoid cross-section coupling via shared
zip_path.Line 177 introduces shared mutable state, and Line 223, Line 290, and Line 358 depend on another
START_SECTIONhaving run first. This makes sections order-dependent and brittle.♻️ Suggested restructuring
-std::string zip_path; +auto createZipFixture = [&]() -> std::string +{ + std::string local_zip_path; + NEW_TMP_FILE(local_zip_path) + local_zip_path += ".zip"; + + int err = 0; + zip_t* archive = zip_open(local_zip_path.c_str(), ZIP_CREATE | ZIP_TRUNCATE, &err); + TEST_NOT_EQUAL(archive, nullptr) + // add file1/file2/file3 + ZIP_CM_STORE ... + TEST_EQUAL(zip_close(archive), 0) + return local_zip_path; +}; START_SECTION(create_uncompressed_zip_archive) { - NEW_TMP_FILE(zip_path) - zip_path += ".zip"; - ... + const std::string zip_path = createZipFixture(); + TEST_EQUAL(zip_path.empty(), false) } END_SECTION START_SECTION(random_access_by_filename) { + const std::string zip_path = createZipFixture(); int err = 0; zip_t* archive = zip_open(zip_path.c_str(), ZIP_RDONLY, &err); TEST_NOT_EQUAL(archive, nullptr)Based on learnings:
Use NEW_TMP_FILE(filename) for each temporary output file in tests to avoid side effects; do not reuse output files across test sections.Also applies to: 220-223, 289-291, 357-359
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/tests/class_tests/openms/source/Libzip_test.cpp` around lines 177 - 183, The test uses a shared mutable variable zip_path across multiple START_SECTION blocks causing order-dependent tests; fix by making each START_SECTION create and use its own temporary filename via NEW_TMP_FILE(local_zip_path) (i.e., declare a local variable instead of reusing the shared zip_path) inside START_SECTION(create_uncompressed_zip_archive) and the other sections that reference zip_path so each test produces/consumes its own .zip file and no section depends on another having run first.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/tests/class_tests/openms/source/Libzip_test.cpp`:
- Around line 111-121: The two ReadAt overrides perform Seek(...) followed by
Read(...) on shared cursor state without synchronization, causing races; add a
mutex (e.g., std::mutex cursor_mutex) as a member of the class that implements
these methods and wrap both ReadAt implementations with a
std::lock_guard<std::mutex> (or std::scoped_lock) to serialize the Seek+Read
pair so the cursor cannot be moved concurrently; ensure both ReadAt(int64_t,
int64_t, void*) and ReadAt(int64_t, int64_t) acquire the same lock before
calling Seek(...) and Read(...), leaving Seek and Read unchanged.
---
Duplicate comments:
In `@src/tests/class_tests/openms/source/Libzip_test.cpp`:
- Around line 177-183: The test uses a shared mutable variable zip_path across
multiple START_SECTION blocks causing order-dependent tests; fix by making each
START_SECTION create and use its own temporary filename via
NEW_TMP_FILE(local_zip_path) (i.e., declare a local variable instead of reusing
the shared zip_path) inside START_SECTION(create_uncompressed_zip_archive) and
the other sections that reference zip_path so each test produces/consumes its
own .zip file and no section depends on another having run first.
| arrow::Result<int64_t> ReadAt(int64_t position, int64_t nbytes, void* out) override | ||
| { | ||
| ARROW_RETURN_NOT_OK(Seek(position)); | ||
| return Read(nbytes, out); | ||
| } | ||
|
|
||
| arrow::Result<std::shared_ptr<arrow::Buffer>> ReadAt(int64_t position, int64_t nbytes) override | ||
| { | ||
| ARROW_RETURN_NOT_OK(Seek(position)); | ||
| return Read(nbytes); | ||
| } |
There was a problem hiding this comment.
Serialize ReadAt to prevent cursor races in Parquet reads.
ReadAt currently does Seek + Read on shared state without locking. If Parquet performs concurrent reads, cursor movement can interleave and return corrupted slices.
🔒 Suggested fix
+#include <mutex>
...
class ZipEntryRandomAccessFile : public arrow::io::RandomAccessFile
{
public:
@@
arrow::Result<int64_t> ReadAt(int64_t position, int64_t nbytes, void* out) override
{
+ std::lock_guard<std::mutex> lock(read_mutex_);
ARROW_RETURN_NOT_OK(Seek(position));
return Read(nbytes, out);
}
arrow::Result<std::shared_ptr<arrow::Buffer>> ReadAt(int64_t position, int64_t nbytes) override
{
+ std::lock_guard<std::mutex> lock(read_mutex_);
ARROW_RETURN_NOT_OK(Seek(position));
return Read(nbytes);
}
private:
+ mutable std::mutex read_mutex_;
zip_t* archive_;
zip_file_t* entry_;In Apache Arrow C++, is `arrow::io::RandomAccessFile::ReadAt` expected to be safe for concurrent calls, and does `parquet::arrow::FileReader::ReadTable` issue parallel column reads by default?
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/tests/class_tests/openms/source/Libzip_test.cpp` around lines 111 - 121,
The two ReadAt overrides perform Seek(...) followed by Read(...) on shared
cursor state without synchronization, causing races; add a mutex (e.g.,
std::mutex cursor_mutex) as a member of the class that implements these methods
and wrap both ReadAt implementations with a std::lock_guard<std::mutex> (or
std::scoped_lock) to serialize the Seek+Read pair so the cursor cannot be moved
concurrently; ensure both ReadAt(int64_t, int64_t, void*) and ReadAt(int64_t,
int64_t) acquire the same lock before calling Seek(...) and Read(...), leaving
Seek and Read unchanged.
|
Looks good to me. |
Summary
Alternative to #8792. Replaces minizip-ng with libzip for ZIP64 archive support.
find_package(libzip REQUIRED)vs 16-line dual-name fallback for minizip-ngapt install libzip-devon Ubuntu (no build-from-source),brew install libzipon macOS,conda install libzipon Windowszip_fseek/zip_fread/zip_ftellprovide true random access on STORE entries (internally mapped tofseekon the physical file), enabling the same Arrow/Parquet-from-ZIP patternReadAtserialized via mutex for safe concurrent Parquet column readsChanges
cmake/cmake_findExternalLibs.cmakefind_package(libzip REQUIRED)replacing minizip-ng dual-name fallbacksrc/openms/CMakeLists.txtlibzip::zipsrc/tests/.../Libzip_test.cppMinizipNG_test.cpp)tools/ci/deps-ubuntu.shapt install libzip-dev(was 11-line build-from-source)tools/ci/deps-macos.shbrew install libzip.github/workflows/openms_ci_matrix_full.ymlconda install libzip(Windows)vcpkg.jsonlibzipdependencycontribTest plan
apt install libzip-dev,find_package(libzip)succeedsbrew install libzip,find_package(libzip)succeedslibzipinstalls,find_package(libzip)succeedsLibzip_testpasses (archive create, random-access read, seek, Parquet roundtrip)🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests
Chores