Skip to content

Release 0.17.9 - #132

Merged
Claptar merged 5 commits into
mainfrom
release/0.17.9
Dec 4, 2026
Merged

Claptar merged 5 commits into
mainfrom
release/0.17.9

Conversation

@Claptar

@Claptar Claptar commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Release 0.17.9: version in pyproject.toml and uv.lock, a ## 0.17.9 section in docs/changelog.md, and STATUS.md. One fix, a security one.

What was wrong. zarr decodes a chunk with whatever codecs its array's metadata names. numcodecs' pickle codec unpickles the chunk, and unpickling runs whatever code the store's author put in it. A Zarr v2 store can name it for any text array, and every AnnData store has two: the obs and var indexes. So reading a crafted store ran its author's code:

  • with exit 0;
  • in convert (to h5ad and to Zarr), subset, split, concat, recast and export;
  • and subset to Zarr copied the codec into its output.

zarr-python and anndata decode such a store the same way. adata already refuses unsafe HDF5 inputs (0.17.5) and loads pickles through an allowlist; Zarr was the gap.

The fix, in two layers:

  1. zarr cannot build a codec off the lists (storage.restrict_zarr_codecs, run when adata.storage is imported). Every chunk is decoded by codecs built from metadata, through numcodecs' registry for v2 and zarr's for v3.
    • Each id off the lists is replaced there by a class that refuses to be built.
    • The functions that build codecs refuse such an id even if something registers it later. These are numcodecs' get_codec, zarr's get_codec_class, and the name zarr's v3 metadata parser imported.
    • This is the layer that holds. It covers metadata the walk below never sees, and metadata changed after a store was opened.
  2. A store is refused up front, naming the array.
    • open_store walks every array zarr lists, through the metadata that read uses.
    • When zarr refuses while parsing, before the walk can name the array, the store's metadata files are read to name it.
    • copy_path (import, --inplace) reads every metadata file the copy would carry as JSON before copying: the arrays' own, the consolidated index, and any index a group's metadata embeds. So no output carries the codec on.
    • The refusal is one Error: line.

The lists. I read the decode() of each of the 26 codecs numcodecs 0.16.5 registers.

  • v2: every codec that only compresses or transforms bytes, numbers or length-prefixed text. Out of the list: pickle, which runs code, and json2 and msgpack2, which build Python objects in a shape the chunk names. anndata writes none of the three.
  • v3: zarr's own codecs plus numcodecs' numcodecs.* wrappers. zarr resolves no v3 codec that runs code; the list keeps a plugin from adding one.

Review. An independent reviewer went over it twice.

  • First pass: the first version only walked the arrays members() lists, and zarr reads more.

    • A path looked up in one go reached an array below a folder with no group metadata, or one hidden by an index embedded in a group's metadata. export array and concat ran the payload that way, with exit 0.
    • A copy could carry a codec that only the on-disk files named.
    • Layer 1 exists because of this pass.
  • Second pass: no way left for adata to build or decode an off-list codec, on zarr 3.4.1 / numcodecs 0.16.5 or at the floors (zarr 3.2.0 / numcodecs 0.14.0). But the copy scan could be fooled:

    • it trusted a .zarray's "node_type" claim;
    • it matched names exactly, so it missed .ZARRAY, which zarr opens on a case-insensitive filesystem;
    • and the source could change between the check and the copy.

    The scan now opens the four metadata names through the filesystem, as zarr does, and checks every compressor, filters and codecs entry whatever the file claims. It also checks the copy once it is made.

Each of these is a test.

Tests: tests/test_zarr_safety.py, 39 tests. The crafted stores carry a payload that only creates a marker file, and the marker is the oracle.

  • Every command refuses with exit 1, one Error: line and no output: ls, view, convert (to h5ad and to Zarr), subset, split, concat, recast, export dataframe/array, import dict/array.
  • Where the codec hides: compressor or filter; in the consolidated index or on disk; an array no listing shows (two ways); metadata changed after opening; a shard's nested codecs.
  • Copies: every metadata file a copy would carry is checked, read as zarr reads it (whatever its claimed version, .ZARRAY where the filesystem ignores case), and the copy is checked again once made. A metadata file that is not JSON is refused. Neither lzma's own filter chain nor attributes are mistaken for codecs.
  • The guard itself: numcodecs and zarr refuse to build a codec off the lists, and a second run of the guard changes nothing.
  • What still works: every element kind anndata writes opens, on Zarr v2 and sharded v3; the check fetches only metadata; a stray .DS_Store prints nothing.
  • The tests can fail. With both layers undone, 29 of the first 35 fail and 10 more error at teardown because the payload ran. The four copy-scan tests fail against the first scan.
  • Elsewhere:
    • the tests pass at the dependency floors (zarr 3.2.0, numcodecs 0.14.0);
    • the unit suite and the 209 cost guards pass locally;
    • so do the anndata 0.7.8–0.13 version tests, which this PR's CI runs too.

Docs:

  • AGENTS.md and developers.md: a new rule that zarr builds only the codecs on the lists.
  • The Zarr specification page: "Codecs read".
  • Troubleshooting: the refusal.
  • The testing map: the new test file.

After this merges, push the tag 0.17.9 from main. Publish then:

  • builds, tests and publishes to PyPI;
  • pushes the image;
  • creates the GitHub release from this section.

A GitHub security advisory for pyadata-cli <= 0.17.8, fixed in 0.17.9, follows the release.

🤖 Generated with Claude Code

Claptar and others added 3 commits December 4, 2026 10:12
zarr decodes a chunk with whatever codecs its array's metadata names, and
numcodecs' pickle codec unpickles it. A Zarr v2 store naming it for a text
array ran its author's code on the first read of that array: convert,
subset, split, concat, recast and export dataframe did, with exit 0, and
subset to Zarr carried the codec into its output.

- storage.check_zarr_contents walks every array's metadata through the
  handle that reads its chunks (the consolidated index when zarr reads
  through one) and refuses a codec outside ZARR_V2_CODECS or
  ZARR_V3_CODECS, naming the array and the codec, before any chunk is
  read. open_store runs it for every mode but a fresh write.
- copy_path checks both the hierarchy on disk and the consolidated index
  before it copies a store, and import's precheck checks the source it
  opens.
- The v2 list is every numcodecs codec whose decode only compresses or
  transforms bytes, numbers or length-prefixed text: not pickle, nor json2
  and msgpack2, which build Python objects in a shape the chunk names.
  The v3 list is zarr's own codecs and numcodecs' wrappers.
- tests/test_zarr_safety.py: every command refuses a store whose payload
  would leave a marker; the codec as compressor or filter, in either
  metadata, or nested in a shard; anndata's v2 and sharded v3 stores still
  open; the check fetches metadata only.
- Docs: Codecs read on the Zarr spec page, the refusal in
  troubleshooting, the new test file in the testing map.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Zarr store naming a codec adata does not decode is refused when it is
opened; numcodecs' pickle codec ran a crafted store's code on read.

- pyproject.toml and uv.lock at 0.17.9.
- docs/changelog.md: a 0.17.9 section (Fixed).
- STATUS.md: 0.17.9 released; the December audit in progress, its epic to
  follow the release; the Zarr hardening follow-up narrowed to what
  remains.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The walk at opening saw only the arrays zarr lists, and zarr reads more:
a path looked up in one go reached an array below a folder with no group
metadata, or one hidden by an index a group's metadata embeds, and
`export array` and `concat` ran the payload that way with exit 0;
metadata re-read after the check was decoded as it then said; and a copy
could carry a codec only the files on disk named.

- restrict_zarr_codecs, run when adata.storage is imported: every codec
  id off the lists resolves, in numcodecs' registry and zarr's, to a class
  that refuses to be built, and numcodecs' get_codec and zarr's
  get_codec_class (with the name zarr's v3 parser imported) refuse such an
  id even if it is registered later. This is the layer that holds.
- open_store keeps its walk for the message, and when zarr refuses while
  parsing, reads the store's metadata files to name the array.
- check_zarr_store reads every metadata file a copy would carry as JSON
  (the arrays' own, the consolidated index, any index a group's metadata
  embeds), through linked folders as the copy goes; one that is not JSON
  is refused.
- The walk no longer prints zarr's warning about a stray file.
- Tests: an array no listing shows, two ways; metadata changed after
  opening; each metadata file a copy carries; the registries refuse and a
  second run changes nothing; a refusal is one Error: line.
- AGENTS.md and developers.md: the rule; the spec, troubleshooting and
  changelog describe both layers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings December 4, 2026 11:00

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T11:01:59.691719Z 76cf192 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Test Results (py3.13)

3 881 tests   3 868 ✅  8m 29s ⏱️
    1 suites     13 💤
    1 files        0 ❌

Results for commit 7f8e339.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Test Results (py3.12)

3 881 tests   3 868 ✅  9m 46s ⏱️
    1 suites     13 💤
    1 files        0 ❌

Results for commit 7f8e339.

♻️ This comment has been updated with latest results.

The scan before a copy matched file names exactly and took an array's
word for its version, so a `.zarray` saying `"node_type": "array"` had
its compressor skipped, and on a case-insensitive filesystem `.ZARRAY`
(which zarr opens as `.zarray`) was not read at all. With the array where
no listing of the copy shows it, `import -o` wrote a store that runs the
payload in any reader; adata itself never decoded it.

- In each folder the four metadata names are opened through the
  filesystem, as zarr opens them.
- Every mapping holding a compressor, filters or codecs is checked,
  whatever it says it is; a codec's own configuration (lzma's filter
  chain) and attributes are not looked into.
- copy_path checks the copy again once it is made, and removes it if it
  is refused: the source may change between the check and the copy.
- restrict_zarr_codecs says that importing adata.storage restricts zarr
  for whatever else the process does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants