Skip to content
Open
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
6 changes: 6 additions & 0 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,12 @@ impl<'wasm> Reader<'wasm> {
VA: Allocator,
{
let len = self.read_u32()?;
// Reject lengths that cannot form a valid allocation layout. On 32-bit
// targets Layout::array overflows for huge declared lengths and used to
// panic inside Vec::new_in; return VecTooLong like the stack path (#158).
Comment on lines +468 to +470

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these comments, I'd rather avoid superfluous comments explaining self document code. The regression test comments are good enough.

if core::alloc::Layout::array::<T>(len as usize).is_err() {
return Err(ValidationError::VecTooLong);
}
let mut out = Vec::new_in(alloc, len)?;
for _ in 0..len {
out.push(read_element(self)?);
Expand Down
9 changes: 9 additions & 0 deletions tests/regression/decode-errors.wast
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,12 @@
(assert_invalid
(module binary "\00asm\01\00\00\00\01\04\01\60\00\00\03\02\01\00\0a\08\01\06\01\ff\ff\03\7f\0b")
"call frame too large")

;; ---------------------------------------------------------------------------
;; A type section declaring 0xFFFFFFFF entries must not panic the heap vector
;; path on 32-bit targets (Layout::array overflow). Regression for #158.
;; ---------------------------------------------------------------------------
(assert_invalid
(module binary "\00asm\01\00\00\00\01\05\ff\ff\ff\ff\0f")
"length out of bounds")

Loading