Skip to content

Use libzip instead of minizip-ng for ZIP64 archive support - #8808

Merged
timosachsenberg merged 8 commits into
developfrom
use-libzip
Feb 27, 2026
Merged

timosachsenberg merged 8 commits into
developfrom
use-libzip

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Feb 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Alternative to #8792. Replaces minizip-ng with libzip for ZIP64 archive support.

  • Simpler CMake: single find_package(libzip REQUIRED) vs 16-line dual-name fallback for minizip-ng
  • Simpler CI: apt install libzip-dev on Ubuntu (no build-from-source), brew install libzip on macOS, conda install libzip on Windows
  • Equivalent functionality: libzip's zip_fseek/zip_fread/zip_ftell provide true random access on STORE entries (internally mapped to fseek on the physical file), enabling the same Arrow/Parquet-from-ZIP pattern
  • Thread-safe Arrow adapter: ReadAt serialized via mutex for safe concurrent Parquet column reads
  • ZIP64 handled transparently by libzip (no explicit flags needed)

Changes

File Change
cmake/cmake_findExternalLibs.cmake find_package(libzip REQUIRED) replacing minizip-ng dual-name fallback
src/openms/CMakeLists.txt Link libzip::zip
src/tests/.../Libzip_test.cpp New test using libzip API (replaces MinizipNG_test.cpp)
tools/ci/deps-ubuntu.sh apt install libzip-dev (was 11-line build-from-source)
tools/ci/deps-macos.sh brew install libzip
.github/workflows/openms_ci_matrix_full.yml conda install libzip (Windows)
vcpkg.json libzip dependency
contrib Submodule updated with libzip 1.11.4 build script (OpenMS/contrib#170)

Test plan

  • Ubuntu CI: apt install libzip-dev, find_package(libzip) succeeds
  • macOS CI: brew install libzip, find_package(libzip) succeeds
  • Windows CI: conda libzip installs, find_package(libzip) succeeds
  • OpenMS builds and links against libzip on all platforms
  • Libzip_test passes (archive create, random-access read, seek, Parquet roundtrip)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Integrated libzip to enable ZIP/ZIP64 archive support and ZIP-backed random-access reading of Parquet files.
  • Tests

    • Added comprehensive ZIP tests: creation, entry validation, random-access reads, and Parquet round-trip via ZIP.
  • Chores

    • Updated build and CI dependency lists and test linking across platforms to include libzip; configuration now requires libzip presence.

timosachsenberg and others added 4 commits February 24, 2026 09:09
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]>
@coderabbitai

coderabbitai Bot commented Feb 26, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
CI & Packaging
​.github/workflows/openms_ci_matrix_full.yml, tools/ci/deps-macos.sh, tools/ci/deps-ubuntu.sh, vcpkg.json
Add libzip to dependency installs (Windows conda, macOS brew, Ubuntu apt, vcpkg).
CMake Build Configuration
cmake/cmake_findExternalLibs.cmake, cmake/Modules/FindLibzip.cmake, src/openms/CMakeLists.txt
Add FindLibzip module and find_package(Libzip REQUIRED), provide imported target libzip::zip, and add it to OPENMS private linkage; configuration fails if Libzip missing.
Tests (build & registration)
src/tests/class_tests/openms/CMakeLists.txt, src/tests/class_tests/openms/executables.cmake
Register Libzip_test, link libzip::zip unconditionally, and add Arrow/Parquet linking and WITH_PARQUET define when enabled.
Tests (implementation)
src/tests/class_tests/openms/source/Libzip_test.cpp
Add ZipEntryRandomAccessFile adapter and tests: create/read uncompressed ZIP entries, random access and seek within entries, enumerate STORE entries, and (gated by WITH_PARQUET) Parquet round-trip via ZIP-backed RandomAccessFile.
Submodule pointer
contrib
Update tracked submodule commit reference (pointer change only).

Sequence Diagram

sequenceDiagram
    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
Loading

Possibly related PRs

Poem

🐇
I nibble bytes and tuck them tight in zip,
hops of random reads — a nimble little trip,
Parquet pages peek through folded seams,
tests confirm the rabbit's data dreams,
hooray — the archive hops, commit and skip!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.26% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: replacing minizip-ng with libzip for ZIP64 support, which aligns with all major modifications across CMake, CI dependencies, and test files.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch use-libzip

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.

@coderabbitai coderabbitai 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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 55f9a70 and c484237.

📒 Files selected for processing (10)
  • .github/workflows/openms_ci_matrix_full.yml
  • cmake/cmake_findExternalLibs.cmake
  • contrib
  • src/openms/CMakeLists.txt
  • src/tests/class_tests/openms/CMakeLists.txt
  • src/tests/class_tests/openms/executables.cmake
  • src/tests/class_tests/openms/source/Libzip_test.cpp
  • tools/ci/deps-macos.sh
  • tools/ci/deps-ubuntu.sh
  • vcpkg.json

Comment on lines +62 to +71
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();
}

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.

⚠️ Potential issue | 🟠 Major

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.

Comment on lines +177 to +183
std::string zip_path;

START_SECTION(create_uncompressed_zip_archive)
{
NEW_TMP_FILE(zip_path)
zip_path += ".zip";

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.

⚠️ Potential issue | 🟠 Major

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)
   ...
 }
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, 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).

timosachsenberg and others added 2 commits February 26, 2026 14:45
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]>

@coderabbitai coderabbitai 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.

♻️ Duplicate comments (2)
src/tests/class_tests/openms/source/Libzip_test.cpp (2)

62-71: ⚠️ Potential issue | 🟠 Major

Guard 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 dereference entry_ unconditionally. Calls after Close() can crash instead of returning an arrow::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.cpp

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 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 | 🟠 Major

Avoid cross-section state coupling via shared zip_path.

zip_path is 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1692dfc and af48a89.

📒 Files selected for processing (3)
  • cmake/Modules/FindLibzip.cmake
  • cmake/cmake_findExternalLibs.cmake
  • src/tests/class_tests/openms/source/Libzip_test.cpp

@timosachsenberg

timosachsenberg commented Feb 26, 2026 •

Copy link
Copy Markdown
Contributor Author

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]>

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/tests/class_tests/openms/source/Libzip_test.cpp (1)

177-183: ⚠️ Potential issue | 🟠 Major

Avoid 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_SECTION having 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.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0e3a374 and 2d759af.

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

Comment on lines +111 to +121
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);
}

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.

⚠️ Potential issue | 🟠 Major

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.

@pjones

pjones commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

Looks good to me.

@timosachsenberg
timosachsenberg merged commit 2a6c65e into develop Feb 27, 2026
50 of 51 checks passed
@timosachsenberg
timosachsenberg deleted the use-libzip branch February 27, 2026 12:09
@coderabbitai coderabbitai Bot mentioned this pull request Mar 4, 2026
5 tasks done
@coderabbitai coderabbitai Bot mentioned this pull request Apr 1, 2026
2 of 4 tasks
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