File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -264,6 +264,10 @@ struct TableEntity /* : ~Copyable */ {
264264 let tableType : TableType
265265 var limits : Limits { tableType. limits }
266266
267+ static func maxSize( isMemory64: Bool ) -> UInt64 {
268+ return UInt64 ( UInt32 . max)
269+ }
270+
267271 init ( _ tableType: TableType , resourceLimiter: any ResourceLimiter ) throws {
268272 let emptyElement : Reference
269273 switch tableType. elementType {
Original file line number Diff line number Diff line change @@ -69,6 +69,9 @@ struct ModuleValidator {
6969 for memoryType in module. memoryTypes {
7070 try Self . checkMemoryType ( memoryType, features: module. features)
7171 }
72+ for tableType in module. tableTypes {
73+ try Self . checkTableType ( tableType, features: module. features)
74+ }
7275 try checkStartFunction ( )
7376 }
7477
@@ -107,6 +110,29 @@ struct ModuleValidator {
107110 }
108111 }
109112
113+ static func checkTableType( _ type: TableType , features: WasmFeatureSet ) throws {
114+ if type. elementType != . funcRef, !features. contains ( . referenceTypes) {
115+ throw ValidationError ( " reference-types feature is required for non-funcref tables " )
116+ }
117+ try checkLimit ( type. limits)
118+
119+ if type. limits. isMemory64 {
120+ guard features. contains ( . memory64) else {
121+ throw ValidationError ( " memory64 feature is required for 64-bit tables " )
122+ }
123+ }
124+
125+ let hardMax = TableEntity . maxSize ( isMemory64: type. limits. isMemory64)
126+
127+ if type. limits. min > hardMax {
128+ throw ValidationError ( " size minimum must not be greater than \( hardMax) " )
129+ }
130+
131+ if let max = type. limits. max, max > hardMax {
132+ throw ValidationError ( " size maximum must not be greater than \( hardMax) " )
133+ }
134+ }
135+
110136 private static func checkLimit( _ limit: Limits ) throws {
111137 guard let max = limit. max else { return }
112138 if limit. min > max {
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ final class SpectestTests: XCTestCase {
2222 path: Self . testPaths,
2323 include: [ ] ,
2424 exclude: [
25- " table .wast" ,
25+ " /br_table .wast" ,
2626 " table_get.wast " ,
2727 " table_grow.wast " ,
2828 " table_size.wast " ,
You can’t perform that action at this time.
0 commit comments