Visitar URL original
Fixed memory bug: properly root repeated/map field when assigning. by haberman · Pull Request #8639 · protocolbuffers/protobuf · GitHub
Skip to content

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

Merged
haberman merged 2 commits into
protocolbuffers:3.17.xfrom
haberman:ruby-mem-fix
May 22, 2021
Merged

haberman merged 2 commits into
protocolbuffers:3.17.xfrom
haberman:ruby-mem-fix

Conversation

@haberman

Copy link
Copy Markdown
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
Copy Markdown
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