ruby-changes:39099
From: nobu <ko1@a...>
Date: Tue, 7 Jul 2015 15:02:41 +0900 (JST)
Subject: [ruby-changes:39099] nobu:r51180 (trunk): file.c: skip invalid byte
nobu 2015-07-07 15:02:21 +0900 (Tue, 07 Jul 2015) New Revision: 51180 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51180 Log: file.c: skip invalid byte * file.c (rb_str_normalize_ospath): skip invalid byte sequence not to loop infinitely. this case usually does not happen as the input name should come from real file systems. Modified files: trunk/ChangeLog trunk/file.c trunk/test/-ext-/string/test_normalize.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 51179) +++ ChangeLog (revision 51180) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Jul 7 15:02:18 2015 Nobuyoshi Nakada <nobu@r...> + + * file.c (rb_str_normalize_ospath): skip invalid byte sequence not + to loop infinitely. this case usually does not happen as the + input name should come from real file systems. + Tue Jul 7 14:40:08 2015 Koichi Sasada <ko1@a...> * vm_backtrace.c: remove debug flag introduced accidentaly. Index: test/-ext-/string/test_normalize.rb =================================================================== --- test/-ext-/string/test_normalize.rb (revision 51179) +++ test/-ext-/string/test_normalize.rb (revision 51180) @@ -59,7 +59,6 @@ class Test_StringNormalize < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/-ext-/string/test_normalize.rb#L59 assert_equal expected, result, "#{expected.dump} is expected but #{src.dump}" end - rescue NotImplementedError end def test_not_normalize_kc @@ -79,7 +78,6 @@ class Test_StringNormalize < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/-ext-/string/test_normalize.rb#L78 assert_equal src, result, "#{src.dump} is expected not to be normalized, but #{result.dump}" end - rescue NotImplementedError end def test_dont_normalize_hfsplus @@ -101,6 +99,11 @@ class Test_StringNormalize < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/-ext-/string/test_normalize.rb#L99 assert_equal src, result, "#{src.dump} is expected not to be normalized, but #{result.dump}" end - rescue NotImplementedError end -end + + def test_invalid_sequence + assert_separately(%w[-r-test-/string/string], <<-'end;') + assert_equal("\u{fffd}", Bug::String.new("\xff").normalize_ospath) + end; + end +end if Bug::String.method_defined?(:normalize_ospath) Index: file.c =================================================================== --- file.c (revision 51179) +++ file.c (revision 51180) @@ -294,6 +294,8 @@ rb_str_normalize_ospath(const char *ptr, https://github.com/ruby/ruby/blob/trunk/file.c#L294 rb_str_append(str, rb_str_normalize_ospath0(p1, p-p1)); rb_str_cat2(str, "\xEF\xBF\xBD"); p += 1; + p1 = p; + continue; } l = MBCLEN_CHARFOUND_LEN(r); c = rb_enc_mbc_to_codepoint(p, e, enc); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/