Skip to content

Fix AttributeError when checking EXT1, EXT2, and EXT4 pickles - #330

Merged
thomas-chauchefoin-tob merged 1 commit into
masterfrom
fix/ext-import-analysis
Oct 14, 2026
Merged

thomas-chauchefoin-tob merged 1 commit into
masterfrom
fix/ext-import-analysis

Conversation

@thomas-chauchefoin-tob

@thomas-chauchefoin-tob thomas-chauchefoin-tob commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

EXT opcodes generate an ast.Import for import copyreg, sys, but both UnsafeImportsML and UnsafeImports accessed node.module as if every import were an ast.ImportFrom. This made check_safety() raise AttributeError instead of returning a verdict, even without registry mutation.

Check every alias in ast.Import nodes and guard ImportFrom-specific checks in both analyzers. Preserve module-prefix matching and the safe-builtin exemption while retaining detection of the sys import.

Fixes #329.

EXT opcodes generate an ast.Import for `import copyreg, sys`, but both
UnsafeImportsML and UnsafeImports accessed node.module as if every import
were an ast.ImportFrom. This made check_safety() raise AttributeError
instead of returning a verdict, even without registry mutation.

Check every alias in ast.Import nodes and guard ImportFrom-specific
checks in both analyzers. Preserve module-prefix matching and the
safe-builtin exemption while retaining detection of the sys import.
@thomas-chauchefoin-tob
thomas-chauchefoin-tob marked this pull request as ready for review October 14, 2026 13:49
@thomas-chauchefoin-tob
thomas-chauchefoin-tob merged commit dc759d0 into master Oct 14, 2026
11 checks passed
@thomas-chauchefoin-tob
thomas-chauchefoin-tob deleted the fix/ext-import-analysis branch October 14, 2026 13:53
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.

check_safety crashes with AttributeError on pickles that use copyreg extension codes (EXT1)

1 participant