[Ruby] Fix: (SIGSEGV) gRPC-Ruby issue on Windows. memory alloc infinite recursion/run out of memory#8195
Merged
haberman merged 1 commit intoprotocolbuffers:masterfrom Jan 8, 2021
Conversation
…alignup(sizeof(mem_block)) is 16
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
Contributor
Author
|
@googlebot I signed it! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On a 32-bit system, sizeof(mem_block) is 8, _upb_arena_alignup(sizeof(mem_block)) is 16.
In https://github.com/protocolbuffers/protobuf/blob/master/ruby/ext/google/protobuf_c/upb.c#L2361, alloc block size is 16384 + 8 bytes,
In https://github.com/protocolbuffers/protobuf/blob/master/ruby/ext/google/protobuf_c/upb.c#L2352, a->head.ptr moves forward 16 bytes.
So in https://github.com/protocolbuffers/protobuf/blob/master/ruby/ext/google/protobuf_c/upb.h#L380, if() is always false, and keeps calling malloc until infinite recursion(O0)/run out of memory(O3)
(gdb) f 16
#16 0x089fb8d0 in upb_arena_allocblock (a=0xa6bf14c, size=16384) at ../../../../ext/google/protobuf_c/upb.c:2361
2361 ../../../../ext/google/protobuf_c/upb.c: No such file or directory.
(gdb) p sizeof(mem_block)
$1 = 8
(gdb) p _upb_arena_alignup(sizeof(mem_block))
$2 = 16
(gdb) p UPB_MAX(size, a->next_block_size)
$3 = 16384
(gdb) f 18
#18 0x089f4d45 in upb_arena_malloc (a=0xa6bf14c, size=16384) at ../../../../ext/google/protobuf_c/upb.h:385
385 ../../../../ext/google/protobuf_c/upb.h: No such file or directory.
(gdb) p h->end - h->ptr
$4 = 16376
(gdb) p size
$5 = 16384
reference: gRPC-Ruby internal issue number b/171421508.
Issue description:
Segfault observed occasionally on Windows, from a cloud logging agent called google-fluentd, which captures logs from different processes on a VM and uses gRPC-Ruby to publish those logs message to a logging service.
How to reproduce:
0.Start a windows VM, e.x. windows 2016 datacenter. RDP into the VM then install the logging agent. Detailed Instruction here: https://cloud.google.com/logging/docs/agent/installation#joint-install
Then Worker 0 finished with signal SIGSEGV. For any large( over 300kb) log file, SIGSEGV shows by 20% chance.