FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Handle MemoryError for sequences by crazymerlyn · Pull Request #5418 · RustPython/RustPython · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .rs  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 11 additions & 2 deletions vm/src/sequence.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL