Skip to content

Commit 546ca81

Browse files
jhawthornHParkerDinah Shi
authored andcommitted
Guard for T_OBJECT at compile time (#53)
Previously this could crash on Nokogiri when JITing the getivar instruction because we would attempt to treat Nokogiri::XML::Document's T_DATA as a T_OBJECT in calling rb_iv_index_tbl_lookup. This commit also checks for T_OBJECT at compile time and emits the rb_ivar_get fallback in that case. Co-authored-by: HParker <HParker@github.com> Co-authored-by: Dinah Shi <dinahshi@github.com> Co-authored-by: HParker <HParker@github.com> Co-authored-by: Dinah Shi <dinahshi@github.com>
1 parent 9283fc1 commit 546ca81

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

yjit_codegen.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,8 @@ gen_get_ivar(jitstate_t *jit, ctx_t *ctx, const int max_chain_depth, VALUE compt
10141014
// NOTE: This assumes nobody changes the allocator of the class after allocation.
10151015
// Eventually, we can encode whether an object is T_OBJECT or not
10161016
// inside object shapes.
1017-
if (rb_get_alloc_func(comptime_val_klass) != rb_class_allocate_instance) {
1017+
if (!RB_TYPE_P(comptime_receiver, T_OBJECT) ||
1018+
rb_get_alloc_func(comptime_val_klass) != rb_class_allocate_instance) {
10181019
// General case. Call rb_ivar_get(). No need to reconstruct interpreter
10191020
// state since the routine never raises exceptions or allocate objects
10201021
// visibile to Ruby.

0 commit comments

Comments
 (0)