File tree Expand file tree Collapse file tree
swift/Sources/FlatBuffers
tests/swift/Tests/Flatbuffers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,8 +56,15 @@ extension Verifiable {
5656 let len : UOffset = try verifier. getValue ( at: position)
5757 let intLen = Int ( len)
5858 let start = Int ( clamping: ( position &+ MemoryLayout< Int32> . size) . magnitude)
59+ let byteCount = intLen. multipliedReportingOverflow (
60+ by: MemoryLayout< T> . size)
61+ guard !byteCount. overflow else {
62+ throw FlatbuffersErrors . outOfBounds (
63+ position: UInt . max,
64+ end: verifier. capacity)
65+ }
5966 try verifier. isAligned ( position: start, type: type. self)
60- try verifier. rangeInBuffer ( position: start, size: intLen )
67+ try verifier. rangeInBuffer ( position: start, size: byteCount . partialValue )
6168 return ( start, intLen)
6269 }
6370}
Original file line number Diff line number Diff line change @@ -411,6 +411,27 @@ final class FlatbuffersVerifierTests {
411411 }
412412 }
413413
414+ @Test ( . bug( " https://github.com/google/flatbuffers/issues/9082 " ) )
415+ func testRejectsTruncatedScalarVector( ) {
416+ // swiftformat:disable all
417+ var byteBuffer = ByteBuffer ( bytes: [
418+ 16 , 0 , 0 , 0 ,
419+ 6 , 0 , 8 , 0 ,
420+ 4 , 0 , 0 , 0 ,
421+ 0 , 0 , 0 , 0 ,
422+ 12 , 0 , 0 , 0 ,
423+ 8 , 0 , 0 , 0 ,
424+ 0 , 0 , 0 , 0 ,
425+ 2 , 0 , 0 , 0 ,
426+ 65 , 66 ,
427+ ] )
428+ // swiftformat:enable all
429+
430+ #expect( throws: FlatbuffersErrors . self) {
431+ try getCheckedRoot ( byteBuffer: & byteBuffer) as Swift_Tests_Vectors
432+ }
433+ }
434+
414435 @Test
415436 func testValidUnionBuffer( ) {
416437 let string = " Awesome \\ \\ t \t \n string! "
You can’t perform that action at this time.
0 commit comments