Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/test/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,16 @@ class CUnpicklerTests(PyUnpicklerTests):
bad_stack_errors = (pickle.UnpicklingError,)
truncated_errors = (pickle.UnpicklingError,)

def test_issue135241(self):
# C implementation should check for hardcoded values 00 and 01
# when getting booleans from the INT opcode. Doing a str comparison
# to bypass truthy/falsy comparisons. These payloads should return
# 0, not False.
out1 = self.loads(b'I+0\n.')
Copy link
Member

Choose a reason for hiding this comment

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

What about b'I001'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The INT opcode only looks specifically for the b'I01' and b'I00' values to convert to True/False. Because of #126992, both implementations specifically use base 10 so b'I001' will push 1 to the stack for both, so that shouldn't be relevant here I don't think.

self.assertTrue(str(out1) == str(0))
out2 = self.loads(b'I 0\n.')
self.assertTrue(str(out2) == str(0))

class CPicklingErrorTests(PyPicklingErrorTests):
pickler = _pickle.Pickler

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The :code:`INT` opcode of the C accelerator ``_pickle`` module was updated to look only for "00" and "01" to push booleans onto the stack, aligning with the Python :mod:`pickle` module.
2 changes: 1 addition & 1 deletion Modules/_pickle.c
Original file line number Diff line number Diff line change
Expand Up @@ -5255,7 +5255,7 @@ load_int(PickleState *state, UnpicklerObject *self)
}
}
else {
if (len == 3 && (x == 0 || x == 1)) {
if (len == 3 && s[0] == '0' && (s[1] == '0' || s[1] == '1')) {
if ((value = PyBool_FromLong(x)) == NULL)
return -1;
}
Expand Down
Loading