mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Fix overflow handling for inplace sequence repetition (#8270)
This commit is contained in:
1 parent
74b598ecac
commit
bb49898b7b
2 files changed
+6
-1
No files matched your search
Vendored
-1
@@ -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()
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user