Skip to content
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

Fixed memory bug: properly root repeated/map field when assigning. #8639

Merged
merged 2 commits into from
May 22, 2021

Conversation

haberman
Copy link
Member

Previously the protobuf extension would not properly root memory from a repeated field or map when assigning to a message field (see the attached test case). If there is no direct reference to the repeated field from Ruby, this will result in a memory error if there is a GC and the repeated field is subsequently accessed (for example, in #encode).

The fix is to do the appropriate upb_arena_fuse() operation when this assignment is performed. This will cause the Union/Find machinery to ensure that the memory for the repeated field or map lives as long as the message.

The the new test case does not actually crash on my machine, but it does trigger a Valgrind error that I can confirm is fixed by the code in this PR. In the future we should make sure that our CI tests are running tests under Valgrind so we can catch future memory errors of this kind.

Also added an explicit check that upb_arena_fuse() succeeded. This is not related to the bugfix, but it is another measure to help ensure that the memory model of the extension is correct.

Fixes: #8559

Previously the protobuf extension would not properly root
memory from a repeated field or map when assigning to a
message field (see the attached test case).  This could cause
crashes if the repeated field is subsequently accessed.
@haberman
Copy link
Member Author

JDK failure is unrelated. Merging.

@haberman haberman merged commit 367e469 into protocolbuffers:3.17.x May 22, 2021
stanhu added a commit to stanhu/pg_query that referenced this pull request May 24, 2021
google-protobuf 3.15.x has a bug that causes a seg fault in Ruby under
certain conditions (protocolbuffers/protobuf#8639). Use
google-protobuf 3.17.1 instead.
lfittl pushed a commit to pganalyze/pg_query that referenced this pull request May 24, 2021
google-protobuf 3.15.x has a bug that causes a seg fault in Ruby under
certain conditions (protocolbuffers/protobuf#8639). Use
google-protobuf 3.17.1 instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants