Skip to content

Commit 556b787

Browse files
Validation: Check table element type in table.copy
1 parent 91eb42c commit 556b787

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

Sources/WasmKit/Translator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,7 @@ struct InstructionTranslator<Context: TranslatorContext>: InstructionVisitor {
20042004
// -----------------------------------------------------------------------------
20052005
// C ⊦ table.copy d s : [iN iM iK] → []
20062006
// https://github.com/WebAssembly/memory64/blob/main/proposals/memory64/Overview.md
2007+
try validator.validateTableCopy(dest: dstTable, source: srcTable)
20072008
let destIsMemory64 = try module.isMemory64(tableIndex: dstTable)
20082009
let sourceIsMemory64 = try module.isMemory64(tableIndex: srcTable)
20092010
let lengthIsMemory64 = destIsMemory64 && sourceIsMemory64

Sources/WasmKit/Validator.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ struct InstructionValidator<Context: TranslatorContext> {
4343
}
4444
}
4545

46+
func validateTableCopy(dest: UInt32, source: UInt32) throws {
47+
let tableType1 = try context.tableType(source)
48+
let tableType2 = try context.tableType(dest)
49+
guard tableType1.elementType == tableType2.elementType else {
50+
throw ValidationError("Table element type mismatch in table.copy: \(tableType1.elementType) != \(tableType2.elementType)")
51+
}
52+
}
53+
4654
func validateRefFunc(functionIndex: UInt32) throws {
4755
try context.validateFunctionIndex(functionIndex)
4856
}

Tests/WasmKitTests/SpectestTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ final class SpectestTests: XCTestCase {
2222
path: Self.testPaths,
2323
include: [],
2424
exclude: [
25-
"table-sub.wast",
2625
"table.wast",
2726
"table_get.wast",
2827
"table_grow.wast",

0 commit comments

Comments
 (0)