diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-08-17 07:23:03 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-08-17 07:23:03 +0000 |
commit | 7766666aed80c7e06dfd8288302a663638b66fe5 (patch) | |
tree | cc987648ae9dc0c49e4099c89f251044ecc40aa3 | |
parent | b2bb02940199c3a540e903e9bb5b31abbf26f4aa (diff) |
merge revision(s) 51037: [Backport #11277]
* transcode.c (load_transcoder_entry): fix transcoder loading race
condition, by waiting in require. [ruby-dev:49106] [Bug #11277]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@51598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | test/ruby/test_transcode.rb | 18 | ||||
-rw-r--r-- | transcode.c | 5 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 25 insertions, 5 deletions
@@ -1,3 +1,8 @@ +Mon Aug 17 16:22:28 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * transcode.c (load_transcoder_entry): fix transcoder loading race + condition, by waiting in require. [ruby-dev:49106] [Bug #11277] + Mon Aug 17 16:18:13 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> * array.c (ary_ensure_room_for_push): check if array size will diff --git a/test/ruby/test_transcode.rb b/test/ruby/test_transcode.rb index 5f3f51a676..8fc0ee1b9d 100644 --- a/test/ruby/test_transcode.rb +++ b/test/ruby/test_transcode.rb @@ -2091,4 +2091,22 @@ class TestTranscode < Test::Unit::TestCase assert_equal("\x00\x00\xFE\xFF\x00\x00\x00t\x00\x00\x00e\x00\x00\x00s\x00\x00\x00t", result.b, bug) end; end + + def test_loading_race + assert_separately([], <<-'end;') #do + bug11277 = '[ruby-dev:49106] [Bug #11277]' + num = 2 + th = (0...num).map do |i| + Thread.new {"\u3042".encode("EUC-JP")} + end + result = nil + assert_warning("", bug11277) do + assert_nothing_raised(Encoding::ConverterNotFoundError, bug11277) do + result = th.map(&:value) + end + end + expected = "\xa4\xa2".force_encoding(Encoding::EUC_JP) + assert_equal([expected]*num, result, bug11277) + end; + end end diff --git a/transcode.c b/transcode.c index 0182a205c2..1cb5631bce 100644 --- a/transcode.c +++ b/transcode.c @@ -372,15 +372,12 @@ load_transcoder_entry(transcoder_entry_t *entry) char *const path = RSTRING_PTR(fn); const int safe = rb_safe_level(); - entry->lib = NULL; - memcpy(path, transcoder_lib_prefix, sizeof(transcoder_lib_prefix) - 1); memcpy(path + sizeof(transcoder_lib_prefix) - 1, lib, len); rb_str_set_len(fn, total_len); FL_UNSET(fn, FL_TAINT); OBJ_FREEZE(fn); - if (!rb_require_safe(fn, safe > 3 ? 3 : safe)) - return NULL; + rb_require_safe(fn, safe > 3 ? 3 : safe); } if (entry->transcoder) @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.1.7" #define RUBY_RELEASE_DATE "2015-08-17" -#define RUBY_PATCHLEVEL 381 +#define RUBY_PATCHLEVEL 382 #define RUBY_RELEASE_YEAR 2015 #define RUBY_RELEASE_MONTH 8 |