google / flatbuffers

FlatBuffers: Memory Efficient Serialization Library
https://flatbuffers.dev/
Apache License 2.0
22.52k stars 3.19k forks source link

Buffer generated in python gets rejected by flatcc [Python / C, Flatbuffer 23.5.26] #8248

Open MaximeLucasSky opened 4 months ago

MaximeLucasSky commented 4 months ago

I am encoding a flatbuffer with python bindings, and am trying to validate it in C using XXX_verify_as_root_with_identifier, which is failing. I believe the issue occures because of a wrong table size generated by can be seen in the fllowing excerpt of the annotated output:

vtable (Affine, CalibData):
  +0x0A62 | 0A 00                   | uint16_t   | 0x000A (10)                       | size of this vtable
  +0x0A64 | 0C 00                   | uint16_t   | 0x000C (12)                       | size of referring table
  +0x0A66 | 0C 00                   | VOffset16  | 0x000C (12)                       | offset to field `temp_range` (id: 0)
  +0x0A68 | 08 00                   | VOffset16  | 0x0008 (8)                        | offset to field `a` (id: 1)
  +0x0A6A | 04 00                   | VOffset16  | 0x0004 (4)                        | offset to field `b` (id: 2)

table (Affine):
  +0x0A6C | 0A 00 00 00             | SOffset32  | 0x0000000A (10) Loc: 0x0A62       | offset to vtable
  +0x0A70 | AC 01 00 00             | UOffset32  | 0x000001AC (428) Loc: 0x0C1C      | offset to field `b` (vector)
  +0x0A74 | 18 00 00 00             | UOffset32  | 0x00000018 (24) Loc: 0x0A8C       | offset to field `a` (vector)
  +0x0A78 | 00 00 00 00 00 00 59 C0 | double     | 0xC059000000000000 (-100)         | struct field `temp_range.inf` of 'TempRange' (Double)
  +0x0A80 | 00 00 00 00 00 00 59 40 | double     | 0x4059000000000000 (100)          | struct field `temp_range.sup` of 'TempRange' (Double)

and here is an excerpt of the schema :

struct TempRange{
    inf:double;
    sup:double;
}

table Polynom {
    coeffs:[double];
}

table Affine{
    temp_range:TempRange;
    a:[Polynom];  
    b:[Polynom];  
}

The issue seems to be that, in the vtable, the size of the referring table is 12, which is too small to take into account the TempRange struct. Is this indeed an encoder error ? Or is it a false positive of the verifier ?

mjdorma commented 1 month ago

Is it possible, in Python, that you are creating the struct temp_range:TempRange before beginning the Affine table?