mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
(fix): #8408 fixes a bug where the capacity of the buffer isnt verified before trying to verify the ID (#8413)
This commit is contained in:
@@ -19,6 +19,8 @@ import Foundation
|
||||
/// Collection of thrown from the Flatbuffer verifier
|
||||
public enum FlatbuffersErrors: Error, Equatable {
|
||||
|
||||
/// Thrown when trying to verify a buffer that doesnt have the length of an ID
|
||||
case bufferDoesntContainID
|
||||
/// Thrown when verifying a file id that doesnt match buffer id
|
||||
case bufferIdDidntMatchPassedId
|
||||
/// Prefixed size doesnt match the current (readable) buffer size
|
||||
|
||||
@@ -201,8 +201,12 @@ public struct Verifier {
|
||||
_depth -= 1
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
mutating func verify(id: String) throws {
|
||||
let size = MemoryLayout<Int32>.size
|
||||
guard _capacity >= (size * 2) else {
|
||||
throw FlatbuffersErrors.bufferDoesntContainID
|
||||
}
|
||||
let str = _buffer.readString(at: size, count: size)
|
||||
if id == str {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user