@@ -11,6 +11,7 @@ public struct Parser<Stream: ByteStream> {
1111 let stream : Stream
1212 public private( set) var hasDataCount : Bool = false
1313 public let features : WasmFeatureSet
14+ let limits : ParsingLimits
1415
1516 enum NextParseTarget {
1617 case header
@@ -27,6 +28,7 @@ public struct Parser<Stream: ByteStream> {
2728 self . features = features
2829 self . hasDataCount = hasDataCount
2930 self . nextParseTarget = . header
31+ self . limits = . default
3032 }
3133}
3234
@@ -186,7 +188,7 @@ public enum WasmParserError: Swift.Error {
186188 /// The data count and data section length are inconsistent
187189 case inconsistentDataCountAndDataSectionLength( dataCount: UInt32 , dataSection: Int )
188190 /// The local count is too large
189- case tooManyLocals
191+ case tooManyLocals( UInt64 , limit : UInt64 )
190192 /// The type is expected to be a reference type, but it's not
191193 case expectedRefType( actual: ValueType )
192194 /// The instruction is not implemented
@@ -1014,8 +1016,8 @@ extension Parser {
10141016 return ( n, t)
10151017 }
10161018 let totalLocals = localTypes. reduce ( UInt64 ( 0 ) ) { $0 + UInt64( $1. n) }
1017- guard totalLocals < UInt32 . max else {
1018- throw WasmParserError . tooManyLocals
1019+ guard totalLocals < limits . maxFunctionLocals else {
1020+ throw WasmParserError . tooManyLocals ( totalLocals , limit : limits . maxFunctionLocals )
10191021 }
10201022
10211023 let locals = localTypes. flatMap { ( n: UInt32 , type: ValueType ) in
0 commit comments