Repository navigation
Preserve PERSID and BINPERSID persistent_load calls via new_variable() - #333
Open
professor-moody wants to merge 2 commits into
Open
professor-moody wants to merge 2 commits into
professor-moody wants to merge 2 commits into
Conversation
professor-moody
requested a review
from thomas-chauchefoin-tob
as a code owner
October 18, 2026 21:13
ESultanik
self-requested a review
November 6, 2026 00:05
ESultanik
requested changes
Nov 6, 2026
ESultanik
left a comment
Collaborator
There was a problem hiding this comment.
Just a couple issues, I added suggestions that I think resolve them.
| name = "PERSID" | ||
|
|
||
| def run(self, interpreter: Interpreter): | ||
| interpreter.stack.append( |
Collaborator
There was a problem hiding this comment.
Suggested change
| interpreter.stack.append( | |
| var_name = interpreter.new_variable( |
Collaborator
There was a problem hiding this comment.
A PERSID → POP → NONE → STOP sequence receives LIKELY_SAFE with only result = None in its AST, although a custom unpickler executes the callback. Memo reuse can instead execute it repeatedly in decompiled code. We should preserve the call through new_variable(), as NEWOBJ_EX already does. BINPERSID has the same pre-existing flaw; this PR duplicates it for newly supported PERSID.
| [], | ||
| ) | ||
| ) | ||
|
|
Collaborator
There was a problem hiding this comment.
Suggested change
| interpreter.stack.append(ast.Name(var_name, ast.Load())) | |
PersId.run and BinPersId.run pushed the persistent_load call straight onto the interpreter stack, so a later POP dropped it from the AST. PERSID, POP, NONE, STOP (and the BINPERSID equivalent) unparsed to "result = None", although a custom unpickler still runs the callback. Memo reuse could instead repeat the call. Bind each call to a variable with new_variable(), as NEWOBJ_EX does, and push the variable name. Add a POP, a memo-reuse and a benign single-use test for each of PERSID and BINPERSID. AI assistance was used in drafting and validating this change; the patch and tests were reviewed and verified by the author.
Author
|
Thanks @ESultanik! Updated |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Review follow-up for #333, applying the two suggestions on
PersId.runand the same change toBinPersId.run, which the review notes has the same pre-existing flaw.PersId.runandBinPersId.runused to push theUNPICKLER.persistent_load(<pid>)call straight onto the interpreter stack. A later POP then dropped the call from the AST, soPERSID, POP, NONE, STOP(and theBINPERSIDequivalent) unparsed toresult = None, although a custom unpickler still runs the callback. Memo reuse could instead repeat the call.Both calls are now bound to a variable with
new_variable()and the variable name is pushed, asNEWOBJ_EXalready does.Tests added to
test/test_persid_newobjex.py:test_persid_call_survives_popandtest_binpersid_call_survives_pop: the opcode, POP, NONE, STOP sequence keeps exactly oneUNPICKLER.persistent_load('abc')in the unparsed AST;test_persid_call_is_not_repeated_by_memo_reuseandtest_binpersid_call_is_not_repeated_by_memo_reuse: a memoised result referenced twice produces onepersistent_load(call;test_persid_valid_single_use_keeps_one_callandtest_binpersid_valid_single_use_keeps_one_call: the plain opcode, STOP shape still yields one call andcheck_safetyreturns a severity.Verification (Python 3.12.15, the whole
test/directory, no filter): with only the new tests applied to the current PR head, the four POP and memo-reuse tests fail (151 passed); with the source change, 155 passed with no skips. On current master merged with this branch, 161 passed. ruff format and ruff check are clean on both changed files.AI assistance was used in drafting and validating this change; the patch and tests were reviewed and verified by the author.