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

Reject invalid section IDs #6675

Merged
merged 2 commits into from
Jun 18, 2024
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
1 change: 0 additions & 1 deletion scripts/test/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ def get_tests(test_dir, extensions=[], recursive=False):
'utf8-invalid-encoding.wast',
'const.wast',
'address.wast',
'custom.wast', # invalid section ID accepted as Custom, triggering UBSan

# Unlinkable module accepted
'linking.wast',
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ class WasmBinaryReader {
Index startIndex = -1;
std::set<Function::DebugLocation> debugLocation;
size_t codeSectionLocation;
std::set<BinaryConsts::Section> seenSections;
std::unordered_set<uint8_t> seenSections;

// All types defined in the type section
std::vector<HeapType> types;
Expand Down
13 changes: 7 additions & 6 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1784,11 +1784,8 @@ void WasmBinaryReader::read() {
// note the section in the list of seen sections, as almost no sections can
// appear more than once, and verify those that shouldn't do not.
if (sectionCode != BinaryConsts::Section::Custom &&
sectionCode != BinaryConsts::Section::Code) {
if (!seenSections.insert(BinaryConsts::Section(sectionCode)).second) {
throwError("section seen more than once: " +
std::to_string(sectionCode));
}
!seenSections.insert(sectionCode).second) {
throwError("section seen more than once: " + std::to_string(sectionCode));
}

switch (sectionCode) {
Expand Down Expand Up @@ -1837,7 +1834,7 @@ void WasmBinaryReader::read() {
case BinaryConsts::Section::Tag:
readTags();
break;
default: {
case BinaryConsts::Section::Custom: {
readCustomSection(payloadLen);
if (pos > oldPos + payloadLen) {
throwError("bad user section size, started at " +
Expand All @@ -1846,7 +1843,11 @@ void WasmBinaryReader::read() {
" not being equal to new position " + std::to_string(pos));
}
pos = oldPos + payloadLen;
break;
}
default:
throwError(std::string("unrecognized section ID: ") +
std::to_string(sectionCode));
}

// make sure we advanced exactly past this section
Expand Down
Loading