-
Notifications
You must be signed in to change notification settings - Fork 114
Register all global VALUES as mark objects #150
Conversation
Previously it was possible for these objects to be garbage collected (the constants could be unassigned in Ruby) or moved as part of GC compaction (reproducible with GC.verify_compaction_references). This commit marks all the global variables in nokogumbo.c using rb_gc_register_mark_object to ensure that they can't be moved.
Hi, Thanks for this patch! I'm a little surprised that Ruby's garbage collector doesn't treat global variables as GC roots. Does Nokogiri have the same issue? E.g., here. Is this a security issue? E.g., if one of these gets garbage collected, can subsequent calls be exploited to do anything other than crash? |
|
Makes sense. |
Thanks so much for this fix! |
Thank you! |
Test that Ruby objects created in C do not get garbage collected.
Test that Ruby objects created in C do not get garbage collected.
Test that Ruby objects created in C do not get garbage collected.
I just released a new version with your fix. It's available on rubygems. Thanks again! |
Previously it was possible for these objects to be garbage collected (the constants could be unassigned in Ruby) or moved as part of GC compaction (reproducible with
GC.verify_compaction_references
).This commit marks all the global variables in
nokogumbo.c
usingrb_gc_register_mark_object
to ensure that they can't be moved.To test this, I added
GC.verify_compaction_references(toward: :empty, double_heap: true)
after the requires intest/test_nokogumbo.rb
. This guarantees that as many objects are moved as possible.Before
After