swift getCheckedRoot(fileId: ) will assert on buffer < (8?) bytes rather than throw. [swift, swiftc 6.0, OSX, 24.3.25]
Closed this issue · 1 comments
peeeeter commented
let dutData : [UInt8] = [1,2,3]
var buff = ByteBuffer(bytes: dutData)
let foo: Foo = try getCheckedRoot(byteBuffer: &buff, fileId: "ABCD")
FlatBuffers/ByteBuffer.swift:470: Assertion failed: Reading out of bounds is illegal
With try getCheckedRoot(byteBuffer: &buff), throws an out of bounds error (which seems correct), but with "fileid", you get an unrecoverable assert.
mustiikhalil commented
Hey,
Thanks for opening this issue! Yeah, just checked the code and I do see the issue. we directly try to read the ID for the file before verifying if the buffer has enough bytes within it to actually read that string! I've been super busy lately, so I won't be able to fix this anytime soon but I will try to push for a couple of fixes within the swift code soonish hopefully
mutating func verify(id: String) throws {
let size = MemoryLayout<Int32>.size
let str = _buffer.readString(at: size, count: size)
if id == str {
return
}
throw FlatbuffersErrors.bufferIdDidntMatchPassedId
}