From bf1782368dc6fee2d5fb9f4dd0cada2ca04ccb30 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Thu, 3 Nov 2022 10:10:01 -0700 Subject: Fix binary parsing of data segment memory (#5208) The binary parser was eagerly getting the name of memories to set the `memory` field of data segments, but that meant that when the memory names were updated later while parsing the names section, the data segment memory fields would become out of date. Update the issue by deferring setting the `memory` fields like we do for other parts of IR that reference memories. Also fix a segfault in the validator that was triggered by the reproducer for this bug before the bug was fixed. Fixes #5204. --- src/wasm/wasm-validator.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/wasm/wasm-validator.cpp') diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 44ecbe9c9..cb3841197 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -3208,9 +3208,11 @@ static void validateDataSegments(Module& module, ValidationInfo& info) { "passive segment should not have an offset"); } else { auto memory = module.getMemoryOrNull(segment->memory); - info.shouldBeTrue(memory != nullptr, - "segment", - "active segment must have a valid memory name"); + if (!info.shouldBeTrue(memory != nullptr, + "segment", + "active segment must have a valid memory name")) { + continue; + } if (memory->is64()) { if (!info.shouldBeEqual(segment->offset->type, Type(Type::i64), -- cgit v1.2.3