mirror of
https://github.com/python/cpython.git
synced 2026-01-26 21:03:34 +00:00
gh-106287: Do not write objects after an unmarshalling error (GH-132715)
Writing out an object may involve a slot lookup, which is not safe to do with an exception raised. In debug mode an assertion failure will occur if this happens.
This commit is contained in:
parent
94dbce1397
commit
ce8f5f98c6
@ -413,6 +413,26 @@ class BugsTestCase(unittest.TestCase):
|
||||
_, dump_1, _ = assert_python_ok(*args, PYTHONHASHSEED="1")
|
||||
self.assertEqual(dump_0, dump_1)
|
||||
|
||||
def test_unmarshallable(self):
|
||||
# Check no crash after encountering unmarshallable objects.
|
||||
# See https://github.com/python/cpython/issues/106287.
|
||||
fset = frozenset([int])
|
||||
code = compile("a = 1", "<string>", "exec")
|
||||
code = code.replace(co_consts=(1, fset, None))
|
||||
cases = (('tuple', (fset,)),
|
||||
('list', [fset]),
|
||||
('set', fset),
|
||||
('dict key', {fset: 'x'}),
|
||||
('dict value', {'x': fset}),
|
||||
('dict key & value', {fset: fset}),
|
||||
('slice', slice(fset, fset)),
|
||||
('code', code))
|
||||
for name, arg in cases:
|
||||
with self.subTest(name, arg=arg):
|
||||
with self.assertRaisesRegex(ValueError, "unmarshallable object"):
|
||||
marshal.dumps((arg, memoryview(b'')))
|
||||
|
||||
|
||||
LARGE_SIZE = 2**31
|
||||
pointer_size = 8 if sys.maxsize > 0xFFFFFFFF else 4
|
||||
|
||||
|
||||
@ -0,0 +1 @@
|
||||
Skip writing objects during marshalling once a failure has occurred.
|
||||
@ -432,6 +432,10 @@ w_object(PyObject *v, WFILE *p)
|
||||
{
|
||||
char flag = '\0';
|
||||
|
||||
if (p->error != WFERR_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
p->depth++;
|
||||
|
||||
if (p->depth > MAX_MARSHAL_STACK_DEPTH) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user