Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 11 additions & 2 deletions vm/src/sequence.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use crate::{
builtins::PyIntRef, function::OptionalArg, sliceable::SequenceIndexOp, types::PyComparisonOp,
vm::VirtualMachine, AsObject, PyObject, PyObjectRef, PyResult,
builtins::PyIntRef,
function::OptionalArg,
sliceable::SequenceIndexOp,
types::PyComparisonOp,
vm::{VirtualMachine, MAX_MEMORY_SIZE},
AsObject, PyObject, PyObjectRef, PyResult,
};
use optional::Optioned;
use std::ops::{Deref, Range};
Expand Down Expand Up @@ -95,6 +99,11 @@ where
{
fn mul(&self, vm: &VirtualMachine, n: isize) -> PyResult<Vec<T>> {
let n = vm.check_repeat_or_overflow_error(self.as_ref().len(), n)?;

if n > 1 && std::mem::size_of_val(self.as_ref()) >= MAX_MEMORY_SIZE / n {
return Err(vm.new_memory_error("".to_owned()));
}

let mut v = Vec::with_capacity(n * self.as_ref().len());
for _ in 0..n {
v.extend_from_slice(self.as_ref());
Expand Down
2 changes: 2 additions & 0 deletions vm/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub use interpreter::Interpreter;
pub(crate) use method::PyMethod;
pub use setting::Settings;

pub const MAX_MEMORY_SIZE: usize = isize::MAX as usize;

// Objects are live when they are on stack, or referenced by a name (for now)

/// Top level container of a python virtual machine. In theory you could
Expand Down
Loading