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 a panic with an invalid name section #3509

Merged
merged 1 commit into from
Nov 5, 2021
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
10 changes: 10 additions & 0 deletions crates/environ/src/module_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,11 @@ and for re-adding support for interface types you can see this issue:
let mut names = f.get_map()?;
for _ in 0..names.get_count() {
let Naming { index, name } = names.read()?;
// Skip this naming if it's naming a function that
// doesn't actually exist.
if (index as usize) >= self.result.module.functions.len() {
continue;
}
let index = FuncIndex::from_u32(index);
self.result
.module
Expand Down Expand Up @@ -1305,6 +1310,11 @@ and for re-adding support for interface types you can see this issue:
let mut reader = l.get_indirect_map()?;
for _ in 0..reader.get_indirect_count() {
let f = reader.read()?;
// Skip this naming if it's naming a function that
// doesn't actually exist.
if (f.indirect_index as usize) >= self.result.module.functions.len() {
continue;
}
let mut map = f.get_map()?;
for _ in 0..map.get_count() {
let Naming { index, name } = map.read()?;
Expand Down
43 changes: 43 additions & 0 deletions tests/misc_testsuite/empty.wast
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
(module (func (export "empty")))

(invoke "empty")

(module binary
"\00asm\01\00\00\00" ;; module header

"\00" ;; custom section id 0
"\0e" ;; section size
"\04name" ;; this is the `name` custom section
"\01" ;; function name subsection
"\07" ;; function name subsection size
"\01" ;; 1 function name mapping
"\ff\ff\ff\ff\0f" ;; index == u32::MAX
"\00" ;; empty string name
)

(module binary
"\00asm\01\00\00\00" ;; module header

"\00" ;; custom section id 0
"\10" ;; section size
"\04name" ;; this is the `name` custom section
"\02" ;; local name subsection
"\09" ;; local name subsection size
"\01" ;; 1 indirect name map
"\ff\ff\ff\ff\0f" ;; index == u32::MAX (function)
"\01" ;; 1 name mapping
"\00" ;; index == 0 (local)
"\00" ;; empty string name
)

(module binary
"\00asm\01\00\00\00" ;; module header

"\00" ;; custom section id 0
"\10" ;; section size
"\04name" ;; this is the `name` custom section
"\02" ;; local name subsection
"\09" ;; local name subsection size
"\01" ;; 1 indirect name map
"\00" ;; index == 0 (function)
"\01" ;; 1 name mapping
"\ff\ff\ff\ff\0f" ;; index == u32::MAX (local)
"\00" ;; empty string name
)