Skip to content
Open
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
9 changes: 9 additions & 0 deletions src/io/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ impl Limits {
/// This function checks that the current limit allows for reserving the set amount
/// of bytes, it then reduces the limit accordingly.
pub fn reserve(&mut self, amount: u64) -> ImageResult<()> {
if amount > isize::MAX as u64 {
// Memory allocations in Rust cannot exceed isize::MAX bytes. So
// reserving more memory than that is not allowed, even if it would
// fall within the memory budget.
return Err(ImageError::Limits(error::LimitError::from_kind(
error::LimitErrorKind::InsufficientMemory,
)));
}

if let Some(max_alloc) = self.max_alloc.as_mut() {
if *max_alloc < amount {
return Err(ImageError::Limits(error::LimitError::from_kind(
Expand Down
Loading