mirror of
https://github.com/google/flatbuffers.git
synced 2026-11-16 08:56:21 +00:00
[Swift] Verify size-prefixed roots from reader position (#9196)
* [Swift] Verify size-prefixed roots from reader position Validate the size prefix before advancing ByteBuffer.reader, then use the active reader position consistently for root, file identifier, and returned-object verification. Cover malformed decoy roots, oversized prefixes, short identifiers, and valid prefixed identifiers. * Use wrapping arithmetic in Swift verifier --------- Co-authored-by: Darren Carreras <283775510+carrerasdarren-cell@users.noreply.github.com>
This commit is contained in:
co-authored by
Darren Carreras
parent
81edeb17d9
commit
5761d6e67a
@@ -215,12 +215,16 @@ public struct Verifier {
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
func verify(id: String) throws {
|
||||
func verify(id: String, at position: Int) throws {
|
||||
let size = MemoryLayout<Int32>.size
|
||||
guard storage.capacity >= (size &* 2) else {
|
||||
guard
|
||||
position >= 0,
|
||||
position <= storage.capacity,
|
||||
storage.capacity - position >= size &* 2
|
||||
else {
|
||||
throw FlatbuffersErrors.bufferDoesntContainID
|
||||
}
|
||||
let str = _buffer.readString(at: size, count: size)
|
||||
let str = _buffer.readString(at: position &+ size, count: size)
|
||||
if id == str {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user