Skip to content

Commit 2cda196

Browse files
committed
WASMDecoder: throw error when sectionId < expected
1 parent 1dc74c6 commit 2cda196

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/libasr/codegen/wasm_decoder.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,15 @@ class WASMDecoder {
349349
"Expected: 0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00");
350350
}
351351
index += PREAMBLE_SIZE;
352+
uint32_t expected_min_section_id = 1;
352353
while (index < wasm_bytes.size()) {
353354
uint32_t section_id = read_u32(wasm_bytes, index);
354355
uint32_t section_size = read_u32(wasm_bytes, index);
356+
if (section_id < expected_min_section_id) {
357+
throw CodeGenError("DecodeWASM: Invalid sectionId, expected id >= "
358+
+ std::to_string(expected_min_section_id));
359+
}
360+
expected_min_section_id = section_id + 1;
355361
switch (section_id) {
356362
case 1U:
357363
decode_type_section(index);

0 commit comments

Comments
 (0)