summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2023-07-16 11:25:10 +0900
committernagachika <nagachika@ruby-lang.org>2023-07-16 11:25:45 +0900
commit293a00e622da077cd6fad2e4055eb15b081fc2a6 (patch)
treeaba87c121f37b0763ba7c9a3b4adefc4747bbc8e
parent0ba10fd8508b1a2bf7488649ee90622de9bef04a (diff)
merge revision(s) 33edcc112081f96856d52e73253d73c97a5c4a3c,b4e438d8aabaf4bba2b27f374c787543fae07c58: [Backport #19483]
YJIT: Protect strings from GC on String#<< (#7466) Fix https://github.com/Shopify/yjit/issues/310 [Bug #19483] Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com> Co-authored-by: Jimmy Miller <jimmy.miller@shopify.com> --- yjit/src/codegen.rs | 3 +++ 1 file changed, 3 insertions(+) YJIT: Save PC on rb_str_concat (#7586) [Bug #19483] Co-authored-by: Alan Wu <alansi.xingwu@shopify.com> --- test/ruby/test_yjit.rb | 19 +++++++++++++++++++ yjit/src/codegen.rs | 6 ++++-- 2 files changed, 23 insertions(+), 2 deletions(-)
-rw-r--r--test/ruby/test_yjit.rb19
-rw-r--r--version.h2
-rw-r--r--yjit/src/codegen.rs5
3 files changed, 25 insertions, 1 deletions
diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb
index 5da42a1b6f..b90235cd7d 100644
--- a/test/ruby/test_yjit.rb
+++ b/test/ruby/test_yjit.rb
@@ -1182,6 +1182,25 @@ class TestYJIT < Test::Unit::TestCase
RUBY
end
+ def test_str_concat_encoding_mismatch
+ assert_compiles(<<~'RUBY', result: "incompatible character encodings: ASCII-8BIT and EUC-JP")
+ def bar(a, b)
+ a << b
+ rescue => e
+ e.message
+ end
+
+ def foo(a, b, h)
+ h[nil]
+ bar(a, b) # Ruby call, not set cfp->pc
+ end
+
+ h = Hash.new { nil }
+ foo("\x80".b, "\xA1A1".force_encoding("EUC-JP"), h)
+ foo("\x80".b, "\xA1A1".force_encoding("EUC-JP"), h)
+ RUBY
+ end
+
private
def code_gc_helpers
diff --git a/version.h b/version.h
index 8ec0bd9350..7a1c331020 100644
--- a/version.h
+++ b/version.h
@@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 2
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 62
+#define RUBY_PATCHLEVEL 63
#include "ruby/version.h"
#include "ruby/internal/abi.h"
diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs
index 0949363026..f07f5ee3d9 100644
--- a/yjit/src/codegen.rs
+++ b/yjit/src/codegen.rs
@@ -4163,6 +4163,11 @@ fn jit_rb_str_concat(
// Guard that the argument is of class String at runtime.
let arg_type = ctx.get_opnd_type(StackOpnd(0));
+ // Guard buffers from GC since rb_str_buf_append may allocate. During the VM lock on GC,
+ // other Ractors may trigger global invalidation, so we need ctx.clear_local_types().
+ // PC is used on errors like Encoding::CompatibilityError raised by rb_str_buf_append.
+ jit_prepare_routine_call(jit, ctx, asm);
+
let concat_arg = ctx.stack_pop(1);
let recv = ctx.stack_pop(1);