Repository navigation
Conversation
A crafted pickle is refused with an Error line rather than crash the reader, as the docs promise. Lengths a pickle names are held to the bytes it holds, and the sniffer reads only a file's head. Column labels a store cannot hold as names are renamed, and such fragments samples refused. Object integers past int64 keep their values. pandas 3's Arrow text reads, without pyarrow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each pandas class's state is taken only in the form pandas 1.5 to 3 pickles it in, with its values checked: a frame's name and attrs' keys, which pandas' setters hash, must be Python's own values. pandas 1.5's manager state is checked as a built manager is, shapes and positions included, before pandas builds from it. Arrow text's offsets are counted before room is made for its values. A manager shared by many frames is checked once. Names that list otherwise than they count (a table) are refused. A frame's attrs are copied once, not once per column, and an integer past any float is written as text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A value whose parts a pickle shares (a tuple of the same tuple at each level) costs a few bytes a level but comes to twice as many values a level. A key is counted, its shared parts once, against the bytes the pickle holds before anything hashes it, and nested 32 deep at most; refusals show what they name in brief; names must be text or numbers; only text, numbers and flat lists of them are written as text. pandas 3's Arrow text read with its cache and a view's read-only flag, and pandas' NA read as a key under pandas 3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
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.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Test Results (py3.13)4 003 tests 3 990 ✅ 9m 28s ⏱️ Results for commit 999bf2d. |
Test Results (py3.12)4 003 tests 3 990 ✅ 11m 13s ⏱️ Results for commit 999bf2d. |
Batch B2 of #149 (wave 1, for 0.17.11): the pycisTopic pickle reader keeps its documented promise. A crafted pickle is refused with an
Error:line, never a crash, and what it reads is written as anndata would. Pickles stay documented as trusted input, as agreed in #149.Closes #136 (F174, F175, F176, F177, F178, F179, F180).
What changes
convertends with anError:line. The defect's details stay out of this description until the fix is released; the tests show them.range, aRangeIndex, or the shape of an empty array or a sparse matrix may be no longer than the pickle's own bytes. A frame's columns are counted against its blocks before pandas makes room for them, and a frame with no rows names no more columns than the bytes read. The converter compares the name counts with the matrix before listing any names.SNIFF_BYTES(64 KiB), and it stops at the first byte unless that byte opens a pickle. Detecting a large text table (a header starting "B" read as an opcode taking 1.87 GB) no longer reads or inflates it./, or empty, is renamed (a/btoa_b,""to_) with a warning, to a name no other column has, asconvertalready renames a loom's fields. Before,/varwrote an h5ad anndata could not open, and/uns/xa strayuns["x"], both with exit 0. Apath_to_fragmentssample like that is refused before anything is written: renaming it would break its match withsample_idand the cell names, which end with it. anndata refuses both kinds of key itself.string[pyarrow]and pre-2.3StringDtypestates read too. This also clears the STATUS.md follow-up "A pickle holding pandas 3's Arrow strings is refused".formats/pickled.pygoes from 83.4% to 99.6% (with the test files of this batch). The lines left are two__repr__s and two defensive repeats of checks every construction route already makes. Crafted pickles are still loaded in a child process first, then here once the child shows them refused, where coverage sees the check. One table-driven test reaches every refusal, a pickle crafted for each.An independent review of the first commit found no memory-safety bypass, but a few gaps, fixed in the second commit with tests:
lenand listed withlist, which differ for a table. Names must now be a list, a 1-d array, an index or a Series.A second pass of the same review over that commit (third commit):
Docs:
docs/reference/formats/cistopic.md(the checks, pandas 3, column labels and samples),docs/reference/commands.md(the new refusals underconvert),docs/troubleshooting.md(both refusal messages),docs/reference/testing.md(the three test files' rows).Tests
check_formatand pandas'Categorical.from_codescall the crafted objects invalid;/key itself;pd.to_numericreads the integers as uint64;validate(full=True)refuses each malformed layout we refuse;tracemallocpeak while refusing.main's sources: 57 fail there, and the one that passes is a casemainalready refused. Each review round's tests were written against cases reproduced on the commit before it.OK.pytest -m "not integration": 4,203 passed, 9 skipped.pytest -m perf: 209 passed.test_external_readers.py(integration) pass: written under pandas 1.5.3, converted here under pandas 3 and under pandas 2.2.3. The three pickle test files also pass at pandas 2.2.3, the floor.Follow-ups noticed, outside this batch's files
util/names.storablerenames/,"",.and.., but not the names Zarr v2 keeps for its metadata (.zarray,.zattrs,.zgroup,.zmetadata). A column or field with one of those labels still writes a Zarr v2 store (--zarr-format 2) that anndata cannot open, with exit 0. That affects loom's and SCope's fields as much as these frames, so the fix belongs instorable.pickleextra's floor: the floors job resolves the dev extra's pandas 3.0. This batch's reader tests pass at 2.2.3 locally. Tests that read output back with anndata cannot run there, because anndata 0.13 needs pandas 2.3. The integration test converting a pandas 1.5 pickle under pandas 2.2.3 passes.Changelog entry
For 0.17.11's
### Fixed:convert(#136). Pickles are
trusted input, but the reader promises to check what numpy, scipy and
pandas are given before they act on it, and a crafted pickle could get
past that:
convertcrashed, with noError:line. Every object is nowchecked before they act on it.
(#136). A length it
names without holding the data for it, or a value it builds from one part
shared many times over, is held to the bytes it holds, and counted before
anything is made for it: a pickle of a few hundred bytes made the reader
take hundreds of MiB, or gigabytes, before refusing it. Names must be text
or numbers, and only text, numbers and flat lists of them are written as
text.
(#136). The pickle
sniffer reads 64 KiB at most. A table whose header began with "B" was read
as a pickle's 1.87 GB of bytes, and a gzipped one inflated.
/, or empty, are renamed with a warning(#136), as a loom's
fields are:
/varwrote an h5ad anndata could not open, and/uns/xastray
uns["x"], both with exit 0. A sample inpath_to_fragmentslikethat is refused instead, since a renamed key would no longer match
sample_idand the cell names.objectkeep their values past int64(#136): 263 was
written as -263. They are written as uint64, as pandas reads them, and
as floats, with a warning, only where no integer dtype holds them.
(#136). pandas 3 keeps
text in Arrow arrays, whose pickles were refused. Their text is now decoded
without pyarrow, every offset checked first.
🤖 Generated with Claude Code