Skip to content

Commit ccbd238

Browse files
authored
Merge pull request #40 from Shopify/flavorjones-check-ivar-size
ujit getinstancevariable code checks ivar extended table size
2 parents e387d78 + 46cde69 commit ccbd238

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

bootstraptest/test_ujit.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,23 @@ def itself
177177
self
178178
end
179179
}
180+
181+
# Test that getinstancevariable codegen checks for extended table size
182+
assert_equal "nil\n", %q{
183+
class A
184+
def read
185+
@ins1000
186+
end
187+
end
188+
189+
ins = A.new
190+
other = A.new
191+
10.times { other.instance_variable_set(:"@otr#{_1}", 'value') }
192+
1001.times { ins.instance_variable_set(:"@ins#{_1}", 'value') }
193+
194+
ins.read
195+
ins.read
196+
ins.read
197+
198+
p other.read
199+
}

ujit_codegen.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,15 @@ gen_getinstancevariable(jitstate_t* jit, ctx_t* ctx)
525525
test(cb, flags_opnd, imm_opnd(ROBJECT_EMBED));
526526
jnz_ptr(cb, side_exit);
527527

528+
// check that the extended table is big enough
529+
if (ivar_index >= ROBJECT_EMBED_LEN_MAX + 1)
530+
{
531+
// Check that the slot is inside the extended table (num_slots > index)
532+
x86opnd_t num_slots = mem_opnd(32, REG0, offsetof(struct RObject, as.heap.numiv));
533+
cmp(cb, num_slots, imm_opnd(ivar_index));
534+
jle_ptr(cb, side_exit);
535+
}
536+
528537
// Get a pointer to the extended table
529538
x86opnd_t tbl_opnd = mem_opnd(64, REG0, offsetof(struct RObject, as.heap.ivptr));
530539
mov(cb, REG0, tbl_opnd);

0 commit comments

Comments
 (0)