-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
segfault when using a nested flatbuffer #51
Comments
From looking at the generated buffer it appears that the nested buffer is not inserting a 4-byte length field for the ubyte vector containing the nested buffer. EDIT: root cause assumption incorrect - looking further Table unions is an alterative approach that could be used as a workaround until I get this sorted. Some additional hints - You likely only need -lflatccrt unless you want to compile schema in you application, and for debug purposes you want -lflatccrt_d because it has runtime assertions for things like failing to close a table - though it wouldn't have helped here because you use the interface correctly. |
@mikkelfj Thanks! I'm actually switching away from a table union toward nested flatbuffers because the table union approach was no longer serving my needs (basically I'm doing a lot of things like #49 and nesting just makes more sense at this point). I'm needing to do a lot of copying around of flatbuffers, storing them in databases, pulling from the the db and reassembling them in different ways, etc. If you have any ideas for quick fixes, I'm comfortable using it in my codebase and testing it out before you roll it out to master. |
as a side question: |
Just add a member to the root table table in the schema and set the value before starting the nested buffer - no guarantee. But the problem is that buffer_mark can have a 0 value correctly, even for nested buffers. A more detailed fix - (guessing) - but I can't do it without impacting performance - but you could try it as workaround: The buffer_mark MUST have the correct value, so we cannot change it to mark an inner buffer. We also cannot use B->level because a it can vary. The A possibly quick fix is to add a buffer level counter in the builder in buffer start and buffer end. Then check this counter in is_top_buffer. It must return 1 both before and after entering the top-level buffer. So buffer_counter <= 1. (For posterity - these lines won't remain valid after a fix but)
|
A nested buffer doesn't really exist. It is just a ubyte vector with the exception that alignment is different. A nested buffer is an independent binary entity stored in this vector. All the accessors are just sugar around this fact. However, getting the alignment right is tricky, which is what the builder does more than anything else. As such, this buffer must contain a table and not a union. FlatCC also permits use of structs at as buffer roots, but most other bindings do not not, AFAIK. |
You can do something else though: there are variant of start_as_root_with_identifier and as_typed_root. The latter stores the type hash identifier for a given table type. This is in effect a schema independent union assuming you namespace appropriately. EDIT: this is incorrect: you CAN get the buffer verified by using as_typed_root.
What you cannot do is to verify a buffer with a nested buffer and make sure the nested buffer has a specific identifier. This is because there can be many embedded buffers with different identifiers. They will still be verified. And upon access you can make sure the type hash is as expected per the above. |
Assuming you mean:
and mod the schema to be like this:
I already tried it, and it still segfaults :( |
I think it is because the table is still pending on the stack, so emit_start does not move. If you create string, it will likely work - you probably don't even have to store it. |
Seems to work for me. |
On nested buffers as unions: https://github.com/dvidelabs/flatcc#file-and-type-identifiers |
The original idea of the type hash was to avoid having a containing table/buffer and detect a message directly based on the type hash. |
A made a correction to buffers with type hashes - see EDIT above. |
Fixed - it was actually a bit tricky because buffer_mark was used to identify top-level buffers and to ensure that vtables are not shared across different buffers. Therefore I had to introduce nest_id. |
It's working! Thank you! |
First off -- this is probably a foolish error on my part.
But here goes. Given:
With the following schema:
I'm segfaulting on the
uint32_t someId = ns(Payload_someId(nestedPayload));
line:Would you happen to know why? I've basically tried to follow this example:
https://github.com/dvidelabs/flatcc/blob/master/test/monster_test/monster_test.c#L1736
And as far as I can see, I have done so. Hopefully I'm missing something silly?
Also, my build script (linux):
The text was updated successfully, but these errors were encountered: