Skip to content

Commit 392cff4

Browse files
committed
Fix panic if too many elements specified in DefBuffer
If a buffer was created with a given size, but a greater number of elements were then specified, we attempted to copy them all, causing a panic. This would only be done by broken/malicious AML. Fix this by capping the copied elements at the specified buffer size.
1 parent ba676e1 commit 392cff4

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/aml/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,11 +663,18 @@ where
663663
Argument::PkgLength(pkg_length),
664664
Argument::Object(buffer_size),
665665
]);
666-
let buffer_size = buffer_size.clone().unwrap_transparent_reference().as_integer()?;
666+
let buffer_size =
667+
buffer_size.clone().unwrap_transparent_reference().as_integer()? as usize;
667668

668669
let buffer_len = pkg_length - (context.current_block.pc - start_pc);
669-
let mut buffer = vec![0; buffer_size as usize];
670-
buffer[0..buffer_len].copy_from_slice(
670+
let mut buffer = vec![0; buffer_size];
671+
672+
/*
673+
* Copy the supplied elements into the buffer, avoiding a pathological case
674+
* where more elements are supplied than the buffer's size
675+
*/
676+
let to_copy = usize::min(buffer_size, buffer_len);
677+
buffer[0..to_copy].copy_from_slice(
671678
&context.current_block.stream()
672679
[context.current_block.pc..(context.current_block.pc + buffer_len)],
673680
);

0 commit comments

Comments
 (0)