Skip to content

fix: read pickle imports the way loaders do - #172

Merged
lab700xdev merged 6 commits into
mainfrom
remapped-names-and-string-operands
Dec 2, 2026
Merged

lab700xdev merged 6 commits into
mainfrom
remapped-names-and-string-operands

Conversation

@lab700xdev

Copy link
Copy Markdown
Contributor

The pickle scanner read some imports differently from the way Python's loaders do, so a file could run os.system on load and still pass. Five commits, each with its own tests and CHANGELOG entry under Unreleased / Security:

  1. INST imports and codec-shaped pickles. The name INST imports is now judged like any other import, and --lint checks it too. A .pkl / .joblib / .dill / .pickle whose first bytes also look like a zlib or bzip2 header is scanned as a pickle when the compression can't be opened.
  2. Names, operands and damaged codecs.
    • Python 2 names that Python 3 rewrites below protocol 3 (__builtin__.eval, commands.getoutput) are now recognized.
    • Names pushed by STRING / BINSTRING / SHORT_BINSTRING, or taken from the memo, are now read.
    • A compressed pickle with a bad byte near the end is scanned up to the damage and marked incomplete, instead of being skipped.
  3. Dotted names and multi-stream files. Protocol 4+ dotted names such as posixpath / os.system are followed one attribute at a time, as the loader does. Every gzip, bzip2 or LZMA stream in a file is read, not just the first.
  4. Module namespaces. Imports of __builtins__ or __globals__, or of a dotted path through one of them or through __dict__, are CRITICAL. A bare module __dict__ is reported only when the same pickle calls something, because dill writes one.
  5. LZMA by header. LZMA files are recognized by their first two bytes, as joblib does. Small dictionaries and unusual properties are opened.
  6. Builtins that return a namespace. builtins.vars, globals and locals are added to the blocklist. Each returns a namespace that holds __builtins__, which operator.getitem can index.

Files that passed before can now be CRITICAL. No new sink tables are added; the builtins entry gains three names.

Checks:

  • On the first five commits: pytest --cov-fail-under=95, aisbom bypass-scorecard --check and the ci.yml smoke steps all pass.
  • On the sixth: the full suite at 96% coverage and the scorecard pass.
  • 67,611 real model and pickle files from local trees give the same results before and after commits 2–6, in both blocklist and --strict mode.
  • Fuzzing against the stdlib unpicklers found no missed imports.

Costs:

  • The large ordinary pickles we timed take up to about 45% longer than in 1.8.1. Hostile filler takes under 10 s per 10 MB on a laptop.
  • About 10 in 171,000 made-up sparse tensors under .bin / .pt move from MEDIUM to CRITICAL (Legacy Binary).

Not for release yet: CLI releases are on hold, so this lands under Unreleased.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 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-02T03:39:17.081612Z 516eec7 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.

@lab700xdev
lab700xdev merged commit 9f58f8f into main Dec 2, 2026
2 checks passed
@lab700xdev
lab700xdev deleted the remapped-names-and-string-operands branch December 2, 2026 03:48
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.

1 participant