Skip to content

fix: preserve picklescan stack state#910

Open
mldangelo-oai wants to merge 2 commits intomainfrom
mdangelo/codex/picklescan-audit-pass-2
Open

fix: preserve picklescan stack state#910
mldangelo-oai wants to merge 2 commits intomainfrom
mdangelo/codex/picklescan-audit-pass-2

Conversation

@mldangelo-oai
Copy link
Copy Markdown
Contributor

@mldangelo-oai mldangelo-oai commented Apr 10, 2026

Summary

  • Preserve standalone picklescan symbolic stack state for DUP, dict/list/set mutation opcodes, and explicit memo writes before MEMOIZE.
  • Add regressions for SETITEM/SETITEMS operands so nested dangerous globals do not get misattributed as REDUCE call targets.
  • Add a memo-index regression so MEMOIZE after PUT/BINPUT/LONG_BINPUT resolves later BINGET call targets correctly.

Validation

  • uv run pytest packages/modelaudit-picklescan/tests
  • uv run ruff format modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/
  • uv run ruff check --fix modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/
  • uv run mypy modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/
  • uv run pytest -n auto -m "not slow and not integration" --maxfail=1
  • uv run ruff format --check modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/
  • uv run ruff check modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/
  • git diff --check

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced pickle scanning reliability by preserving stack state across memo and container mutation opcodes, preventing state loss during analysis of complex pickle files
  • Tests

    • Added test coverage validating that dictionary mutation patterns and memoization-index behaviors are properly detected as threatening operations during pickle scanning

@mldangelo-oai mldangelo-oai enabled auto-merge (squash) April 10, 2026 17:41
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 42772fb7-ce1d-4751-a902-e006bb70bb22

📥 Commits

Reviewing files that changed from the base of the PR and between f285a05 and fd935af.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • packages/modelaudit-picklescan/src/modelaudit_picklescan/engine/scanner.py
  • packages/modelaudit-picklescan/tests/test_api.py

Walkthrough

This pull request updates the pickle scanner's state management and opcode handling. Changes include resetting memo state only on STOP, implementing explicit stack duplication for DUP, refining memo-write semantics for opcodes like APPEND and SETITEM, and replacing indexed memo tracking with length-based keys. Test coverage is added for detecting dangerous pickle patterns.

Changes

Cohort / File(s) Summary
Documentation
CHANGELOG.md
Added bug fix entry documenting preservation of picklescan stack state across memo and container mutation opcodes.
Scanner Logic
packages/modelaudit-picklescan/src/modelaudit_picklescan/engine/scanner.py
Refactored memo state management to reset only on STOP opcode, added explicit DUP stack duplication, altered memo-write semantics for APPEND/SETITEM/bulk variants, and changed MEMOIZE to use len(self.memo) instead of separate index tracking.
Test Coverage
packages/modelaudit-picklescan/tests/test_api.py
Added two parametrized test cases validating detection of dangerous behavior in dictionary mutation and memoization-index patterns in pickled objects.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🥕 Our scanner hops with sharper sight,
Memo states aligned just right,
Stack and opcodes dance in flow,
Dangerous pickles won't elude, no!
Tests now catch what once slipped by—
Security soars! Bunny says "Hi!" 🐰

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 title 'fix: preserve picklescan stack state' directly corresponds to the main objective and changes in the PR, which focus on preserving stack state across opcodes and memo handling.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mdangelo/codex/picklescan-audit-pass-2

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.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 916cfaf856

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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