diff options
author | Alon Zakai <azakai@google.com> | 2024-11-07 08:34:56 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-07 08:34:56 -0800 |
commit | 0af8f1f2d7ff304837ee0698265c84985420fcae (patch) | |
tree | 5a137b0483b95894126422a31c687054cda5db73 | |
parent | ab8a41c85ddb1ea783bc8a8832254f992262bed6 (diff) | |
download | binaryen-0af8f1f2d7ff304837ee0698265c84985420fcae.tar.gz binaryen-0af8f1f2d7ff304837ee0698265c84985420fcae.tar.bz2 binaryen-0af8f1f2d7ff304837ee0698265c84985420fcae.zip |
[wasm64] Fuzzer: Fix table import operations on table64 (#7056)
The old code assumed the index was a JS number, but if the table has
64-bit indexes it must be a BigInt. Detect that and cast as needed.
-rw-r--r-- | scripts/fuzz_shell.js | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/scripts/fuzz_shell.js b/scripts/fuzz_shell.js index c4c0056f0..72120cf7f 100644 --- a/scripts/fuzz_shell.js +++ b/scripts/fuzz_shell.js @@ -134,6 +134,17 @@ function logValue(x, y) { console.log('[LoggingExternalInterface logging ' + printed(x, y) + ']'); } +// Table get/set operations need a BigInt if the table has 64-bit indexes. This +// adds a proper cast as needed. +function toAddressType(table, index) { + // First, cast to unsigned. We do not support larger indexes anyhow. + index = index >>> 0; + if (typeof table.length == 'bigint') { + return BigInt(index); + } + return index; +} + // Set up the imports. var tempRet0; var imports = { @@ -156,10 +167,10 @@ var imports = { // Table operations. 'table-get': (index) => { - return exports.table.get(index >>> 0); + return exports.table.get(toAddressType(exports.table, index)); }, 'table-set': (index, value) => { - exports.table.set(index >>> 0, value); + exports.table.set(toAddressType(exports.table, index), value); }, }, // Emscripten support. |