ruby-changes:32724
From: nobu <ko1@a...>
Date: Tue, 4 Feb 2014 12:55:38 +0900 (JST)
Subject: [ruby-changes:32724] nobu:r44803 (trunk): string.c: enable capacity when setting capa
nobu 2014-02-04 12:55:32 +0900 (Tue, 04 Feb 2014) New Revision: 44803 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44803 Log: string.c: enable capacity when setting capa * string.c (rb_str_modify_expand): enable capacity and disable assocation with packed objects when setting capa, so that pack("p") string fails to unpack properly after modified. Modified files: trunk/ChangeLog trunk/string.c trunk/test/ruby/test_pack.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 44802) +++ ChangeLog (revision 44803) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Feb 4 12:55:31 2014 Nobuyoshi Nakada <nobu@r...> + + * string.c (rb_str_modify_expand): enable capacity and disable + assocation with packed objects when setting capa, so that + pack("p") string fails to unpack properly after modified. + Tue Feb 4 12:45:15 2014 Nobuyoshi Nakada <nobu@r...> * dir.c (glob_make_pattern): all alphabets are magic characters on Index: string.c =================================================================== --- string.c (revision 44802) +++ string.c (revision 44803) @@ -1503,6 +1503,7 @@ rb_str_modify_expand(VALUE str, long exp https://github.com/ruby/ruby/blob/trunk/string.c#L1503 int termlen = TERM_LEN(str); if (!STR_EMBED_P(str)) { REALLOC_N(RSTRING(str)->as.heap.ptr, char, capa + termlen); + STR_UNSET_NOCAPA(str); RSTRING(str)->as.heap.aux.capa = capa; } else if (capa + termlen > RSTRING_EMBED_LEN_MAX + 1) { Index: test/ruby/test_pack.rb =================================================================== --- test/ruby/test_pack.rb (revision 44802) +++ test/ruby/test_pack.rb (revision 44803) @@ -181,6 +181,7 @@ class TestPack < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_pack.rb#L181 assert_equal a[0], a.pack("p").unpack("p")[0] assert_equal a, a.pack("p").freeze.unpack("p*") assert_raise(ArgumentError) { (a.pack("p") + "").unpack("p*") } + assert_raise(ArgumentError) { (a.pack("p") << "d").unpack("p*") } end def test_format_string_modified -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/