Skip to content

fix: reject pickling writable ZipStore#4168

Open
AMBRA7592 wants to merge 2 commits into
zarr-developers:mainfrom
AMBRA7592:codex/zipstore-pickle-guard
Open

fix: reject pickling writable ZipStore#4168
AMBRA7592 wants to merge 2 commits into
zarr-developers:mainfrom
AMBRA7592:codex/zipstore-pickle-guard

Conversation

@AMBRA7592

@AMBRA7592 AMBRA7592 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Pickling a ZipStore doesn't serialize the archive; it serializes the parameters to reopen it. So pickling is safe exactly when reopening is safe.

For readers (mode="r"), it is: many independent processes can open the same path and just read. Round-trips fine.

For writers, it isn't. A ZIP has one central directory written at close. Fan out several unpickled writers to one path and each rewrites that directory on close; last close wins, the rest is corruption. Since cross-process fan-out is why you pickle at all, the writer pickle path leads straight into the one thing ZIP can't survive. Rejecting at __getstate__ fails fast instead.

Closes #3516.

For reviewers

Keying on _zmode != "r" (not read_only) is right: an append-mode store can be read_only=True yet still rewrite its directory on reopen. Only "r" reopens harmlessly.

Author attestation

  • I am a human, these are my changes, and I have reviewed and understood every change and can explain why each is correct.

TODO

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/user-guide/*.md
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

@github-actions github-actions Bot added the needs release notes Automatically applied to PRs which haven't added release notes label Jul 20, 2026
@github-actions github-actions Bot removed the needs release notes Automatically applied to PRs which haven't added release notes label Jul 20, 2026
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.84%. Comparing base (ecc2d77) to head (64e98cc).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4168   +/-   ##
=======================================
  Coverage   93.84%   93.84%           
=======================================
  Files          91       91           
  Lines       12549    12551    +2     
=======================================
+ Hits        11777    11779    +2     
  Misses        772      772           
Files with missing lines Coverage Δ
src/zarr/storage/_zip.py 97.74% <100.00%> (+0.02%) ⬆️
src/zarr/testing/store.py 98.91% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Writing dask arrays to a ZipStore causes a corrupt zip file

1 participant