Implement EXT1, EXT2, and EXT4 pickle opcode support #172
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implement EXT1, EXT2, and EXT4 Pickle Opcode Support
Problem
Fickling raises NotImplementedError: TODO: Add support for Opcode EXT1 (and EXT2, EXT4) when analyzing pickle files that use extension registry opcodes from pickle protocol 2+.
What Are EXT Opcodes?
EXT opcodes allow pickles to reference pre-registered objects from the global extension registry using integer codes instead of full module/name paths:
These opcodes look up objects in copyreg._extension_registry which maps integer codes to (module, name) tuples.
Solution
Implemented three new opcode classes:
The implementation uses the "Middle Ground" approach:
Example Output
Before: NotImplementedError: TODO: Add support for Opcode EXT1
After:
import copyreg
_var0 = copyreg._extension_registry.get(42, (None, None))
_var1 = _var0()
_var1.setstate({'value': 42})
result0 = _var1
Testing
Benefits