-
Notifications
You must be signed in to change notification settings - Fork 122
Buffer_alloc: initialize the buffer before calling rb_ivar_set
#314
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
Conversation
|
NB: I suspect we might have another bug, because I can't find any place allocating standalone buffers in the application that experienced this crash. So a similar bug might be possible with "shared" buffers, but I couldn't find a repro yet. |
|
Yeah, I confirm this doesn't fix the application in question. So there is another case where we might mark uninitialized buffers. |
3f735a4 to
f08474b
Compare
|
So I tried 906fa01 and it still fail with the same error. If the line numbers in the stacktrace are to be believed we fail on: while(c != &b->tail) {Which makes very little sense as it would suggest if(b->head) {
msgpack_buffer_chunk_t* c = b->head;
while(c != &b->tail) {
rb_gc_mark(c->mapped_string);
c = c->next;
}
rb_gc_mark(c->mapped_string);
}I'll keep digging. |
|
Interestingly in Doesn't make much more sense but... |
|
Another way it crash: |
bd12cb3 to
d0a2bc0
Compare
|
Ok, @peterzhu2118 managed to figure it out by inspecting the core dump. The problem was a name clash with another gem: https://github.com/Shopify/stack_frames/blob/154a360cac62a247fe45a56c698814cf1274c302/ext/stack_frames/buffer.c#L36
The fix is to hide this symbol, as it has no need to be public. The original bug I found is legit though, so I'll cleanup with PR to just be focused on that one bug I found, and I'll open another one to hide the symbols. |
79ec74c to
f08474b
Compare
`rb_ivar_set` may trigger GC, and if it does then we'll try to mark an uninitialized buffer and that will segfault because `b->head == NULL`.
f08474b to
e0b95ec
Compare
Ref: msgpack/msgpack-ruby#314 (comment) We experienced some weird segfault in `msgpack_buffer_mark` we couldn't explain. Until we noticed that the object being marked wasn't a `MessagePack::Buffer` but a `StackFrames::Buffer`. Both `msgpack` and `stackframes` were using the same symbol name to declare their respective buffer type, and the msgpack one was registered first. This is the counterpart of msgpack/msgpack-ruby#317 and generally speaking all gems should compile with `-fvisibility=hidden`.
rb_ivar_setmay trigger GC, and if it does then we'll try to mark an uninitialized buffer and that will segfault becauseb->head == NULL.Should fix:
cc @peterzhu2118