Skip to content

Commit 1f03b22

Browse files
feat(validation): add error for leftover content after last section
Signed-off-by: Florian Hartung <florian.hartung@dlr.de>
1 parent d735bd3 commit 1f03b22

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/core/error.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use core::fmt::{Display, Formatter};
44
use core::str::Utf8Error;
55

66
use super::indices::FuncIdx;
7-
use crate::core::reader::section_header::SectionTy;
87
use crate::core::reader::types::ValType;
98

109
#[derive(Debug, PartialEq, Eq, Clone)]
@@ -71,8 +70,8 @@ pub enum ValidationError {
7170
/// An index for a lane of some vector type is invalid.
7271
InvalidLaneIdx(u8),
7372

74-
/// A section with given type is out of order. All section types have a fixed order in which they must occur.
75-
SectionOutOfOrder(SectionTy),
73+
/// The last section was read, but there is still content in the bytecode.
74+
UnexpectedContentAfterLastSection,
7675
/// A custom section contains more bytes than its section header specifies.
7776
InvalidCustomSectionLength,
7877
ExprMissingEnd,
@@ -201,7 +200,7 @@ impl Display for ValidationError {
201200
ValidationError::InvalidLabelIdx(idx) => write!(f, "The label index {idx} is invalid"),
202201
ValidationError::InvalidLaneIdx(idx) => write!(f, "The lane index {idx} is invalid"),
203202

204-
ValidationError::SectionOutOfOrder(ty) => write!(f, "A section of type `{ty:?}` is defined out of order"),
203+
ValidationError::UnexpectedContentAfterLastSection => write!(f, "The last section was read, but there is still content in the bytecode"),
205204
ValidationError::InvalidCustomSectionLength => write!(f, "A custom section contains more bytes than its section header specifies"),
206205
ValidationError::ExprMissingEnd => write!(f, "An expr type is missing an end byte"),
207206
ValidationError::InvalidInstr(byte) => write!(f, "The instruction opcode {byte:#x} is invalid"),

src/validation/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ pub fn validate(wasm: &[u8]) -> Result<ValidationInfo<'_>, ValidationError> {
345345
while (skip_section(&mut wasm, &mut header)?).is_some() {}
346346

347347
// All sections should have been handled
348-
if let Some(header) = header {
349-
return Err(ValidationError::SectionOutOfOrder(header.ty));
348+
if let Some(_header) = header {
349+
return Err(ValidationError::UnexpectedContentAfterLastSection);
350350
}
351351

352352
debug!("Validation was successful");

0 commit comments

Comments
 (0)