From 9af12c3f6dc0258fe0b045647cbae73bc71ffd8e Mon Sep 17 00:00:00 2001 From: SeungJe Jeong <88067455+seungje0612@users.noreply.github.com> Date: Wed, 15 Jul 2026 23:43:29 +0900 Subject: [PATCH] Fix overflow handling for inplace sequence repetition (#8270) --- Lib/test/test_list.py | 1 - crates/vm/src/sequence.rs | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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 {