Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix validation edge case when function end code is missing #324

Merged
merged 1 commit into from
Jan 31, 2025
Merged
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
2 changes: 2 additions & 0 deletions src/parser/WASMParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate {

virtual void BeginFunctionBody(Index index, Offset size) override
{
ASSERT(resumeGenerateByteCodeAfterNBlockEnd() == 0);
ASSERT(m_currentFunction == nullptr);
beginFunction(m_result.m_functions[index], false);
}
Expand Down Expand Up @@ -1039,6 +1040,7 @@ class WASMBinaryReader : public wabt::WASMBinaryReaderDelegate {
m_preprocessData.m_inPreprocess = false;
m_skipValidationUntil = *m_readerOffsetPointer - 1;
m_shouldContinueToGenerateByteCode = true;
setResumeGenerateByteCodeAfterNBlockEnd(0);

m_currentFunction->m_byteCode.clear();
m_currentFunction->m_catchInfo.clear();
Expand Down
28 changes: 28 additions & 0 deletions test/basic/missing_end.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(assert_invalid
(module binary
"\00asm" "\01\00\00\00"
"\01\09" ;; import section
"\02\60\00\00\60\01\7f\01\7f" ;; type section entry
"\03\02" ;; function section
"\01\00" ;; function section entry
"\07\09" ;; export section
"\01\05\6e\6f\65\6e\64\00\00" ;; export section entry (function 'noend')
"\0a\18" ;; begin code section
"\01\16\00" ;; begin function body
"\02\40" ;; block
"\03\40" ;; loop
"\02\40" ;; block
"\03\40" ;; loop
"\0c\00" ;; br 0
"\02\01" ;; block type[1]
"\0b" ;; end
"\0c\00" ;; br 0
"\0b" ;; end
"\00" ;; unreachable
"\00" ;; unreachable
"\00" ;; unreachable
"\0b" ;; end
"\0b" ;; end
)
"function body must end with END opcode"
)
Loading