gh-142831: Fix UAF in _json module#142851
Conversation
serhiy-storchaka
left a comment
There was a problem hiding this comment.
Could you add tests?
|
Added tests |
|
I pushed a minor test change to make the test run on both pure python and C encoder. |
|
@kumaraditya303 But the new tests don't reproduce the issue! |
This reverts commit 66c3af1.
I was able to reproduce it but now I can't, not sure if it was a build cache issue or something. Sorry reverted it back. |
|
I have made the requested changes; please review again |
|
Thanks for making the requested changes! @serhiy-storchaka, @kumaraditya303: please review the changes made to this pull request. |
…list mutation test" This reverts commit b4e50c9.
# Conflicts: # Modules/_json.c
_json.c is a library module; the identical fix pythongh-145244 used Library.
Match the style of the comment added by pythongh-145244 for the dict iteration case. These explain why borrowed references from items lists and sequences must be held as strong references during encoding.
|
nothing the irony of my commit re-adding explanatory comments that earlier reviewer wanted removed. the other PR I merged intersecting with this region and bug had such a comment so put them in here as well. i'll re-look at the whole and pick a direction in a bit. |
- Replace bare try/except with direct calls; both tests should succeed without raising since encode_str and default return valid serializable values. - Assert that the mutation path was actually exercised (cleared flag, call_count). - Trigger list mutation on 3rd element instead of 1st, so the loop processes multiple items before the list is cleared mid-iteration. - Add comments explaining what each test verifies.
|
Sorry, @ashm-dev and @gpshead, I could not cleanly backport this to |
|
Sorry, @ashm-dev and @gpshead, I could not cleanly backport this to |
json.encodermapping iteration via re-entrant key encoder #142831Fixes #142831