File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -155,12 +155,18 @@ public enum BinaryDelimited {
155155 partial: Bool = false ,
156156 options: BinaryDecodingOptions = BinaryDecodingOptions ( )
157157 ) throws {
158- let length = try Int ( decodeVarint ( stream) )
159- if length == 0 {
158+ let unsignedLength = try decodeVarint ( stream)
159+ if unsignedLength == 0 {
160160 // The message was all defaults, nothing to actually read.
161161 return
162162 }
163-
163+ guard unsignedLength <= Int . max else {
164+ // Due to the trip through an Array below, it has to fit, and Array uses
165+ // Int (signed) for Count.
166+ // Adding a new case is a breaking change, reuse malformedProtobuf.
167+ throw BinaryDecodingError . malformedProtobuf
168+ }
169+ let length = Int ( unsignedLength)
164170 var data = Data ( count: length)
165171 var bytesRead : Int = 0
166172 data. withUnsafeMutableBytes { ( body: UnsafeMutableRawBufferPointer ) in
You can’t perform that action at this time.
0 commit comments