diff --git a/Lib/test/test_list.py b/Lib/test/test_list.py index e320a2008..40cec2261 100644 --- a/Lib/test/test_list.py +++ b/Lib/test/test_list.py @@ -106,7 +106,6 @@ class ListTest(list_tests.CommonTest): x[:] = x self.assertEqual(x, []) - @unittest.skip("TODO: RUSTPYTHON; crash") def test_list_resize_overflow(self): # gh-97616: test new_allocated * sizeof(PyObject*) overflow # check in list_resize() diff --git a/crates/vm/src/sequence.rs b/crates/vm/src/sequence.rs index 0bc12fd26..0bc35181b 100644 --- a/crates/vm/src/sequence.rs +++ b/crates/vm/src/sequence.rs @@ -122,6 +122,12 @@ where fn imul(&mut self, vm: &VirtualMachine, n: isize) -> PyResult<()> { let n = vm.check_repeat_or_overflow_error(self.as_ref().len(), n)?; + + if n > 1 && core::mem::size_of_val(self.as_ref()) >= MAX_MEMORY_SIZE / n { + // TODO: make a global static NoMemory shared exc object and return its reference. + return Err(vm.new_memory_error("")); + } + if n == 0 { self.as_vec_mut().clear(); } else if n != 1 {