syck 1.6.1 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6f8be592c6d196af5a6fbf7bdab813819b4303d817f48b2edbc2e3441362382
4
- data.tar.gz: 309adadd5621cfecdee15f0e36e39b7c1205df6406ab2521cea915b7509196fb
3
+ metadata.gz: e27c3b9b21ba6e707479bdbfeadbd583d68cfef4b6f2e4882faff6316fc09f19
4
+ data.tar.gz: d5bfc236838cee8709f19789e641eadf9c218e39b668db1462a5a704cea444b3
5
5
  SHA512:
6
- metadata.gz: ef57afc974162ffda31cf27709ed5bdad7219f0a181a95a833549d575bfd0edd8fb18967ce380120b477107a643f823294ca83092f17b93a518e49ae59961288
7
- data.tar.gz: abbdbea1f6eaea32d639b8ea9bcaee50c012c2f362d24d7a49489938eb079eb5c813d437bbf002cdb2ff149d323fd7510db3494075f6bb6c9a0f9884ed87a485
6
+ metadata.gz: 4f5de63e2fcd1c793fc25049c3cc36d7fcbb30c661f74b41af5e2f13cdca7145d99820812c6a3729a627810286c2a70b318e3ff2f252f9620514dad9f099ae0f
7
+ data.tar.gz: a98dbb0151212292f8d2cc47ef00730b607fb0032427c0eec333a66a4b52872429f8c85e9e9aa3effc1ae716cf24e92be7920f9ee68bf556021cc3d2955dfdf6
data/ext/syck/rubyext.c CHANGED
@@ -148,6 +148,7 @@ rb_syck_compile(VALUE self, VALUE port)
148
148
  SYMID oid;
149
149
  int taint;
150
150
  char *ret;
151
+ long blen;
151
152
  VALUE bc;
152
153
  bytestring_t *sav = NULL;
153
154
  void *data = NULL;
@@ -160,18 +161,25 @@ rb_syck_compile(VALUE self, VALUE port)
160
161
  syck_parser_taguri_expansion( parser, 0 );
161
162
  oid = syck_parse( parser );
162
163
  if (!syck_lookup_sym( parser, oid, &data )) {
164
+ syck_free_parser( parser );
163
165
  rb_raise(rb_eSyntaxError, "root node <%p> not found", (void *)oid);
164
166
  }
165
167
  sav = data;
166
168
 
167
- ret = S_ALLOCA_N( char, strlen( sav->buffer ) + 3 );
168
- ret[0] = '\0';
169
- strcat( ret, "D\n" );
170
- strcat( ret, sav->buffer );
171
-
169
+ /*
170
+ * Steal the buffer from the parser's symbol table (S_FREE ignores
171
+ * the NULLed pointer) so the parser can be freed before rb_str_new,
172
+ * which may raise and would otherwise leak the parser.
173
+ */
174
+ ret = sav->buffer;
175
+ sav->buffer = NULL;
172
176
  syck_free_parser( parser );
173
177
 
174
- bc = rb_str_new2( ret );
178
+ blen = (long)strlen( ret );
179
+ bc = rb_str_new( 0, blen + 2 );
180
+ memcpy( RSTRING_PTR(bc), "D\n", 2 );
181
+ memcpy( RSTRING_PTR(bc) + 2, ret, (size_t)blen );
182
+ S_FREE( ret );
175
183
  if ( taint ) OBJ_TAINT( bc );
176
184
  return bc;
177
185
  }
@@ -1213,13 +1221,17 @@ syck_set_ivars(
1213
1221
  )
1214
1222
  {
1215
1223
  VALUE ivname = rb_ary_entry( vars, 0 );
1224
+ VALUE ivn_v;
1216
1225
  char *ivn;
1226
+ long ivn_len;
1217
1227
  StringValue( ivname );
1218
- ivn = S_ALLOCA_N( char, RSTRING_LEN(ivname) + 2 );
1228
+ ivn_len = RSTRING_LEN(ivname);
1229
+ ivn = ALLOCV_N( char, ivn_v, ivn_len + 2 );
1219
1230
  ivn[0] = '@';
1220
- ivn[1] = '\0';
1221
- strncat( ivn, RSTRING_PTR(ivname), RSTRING_LEN(ivname) );
1231
+ memcpy( ivn + 1, RSTRING_PTR(ivname), (size_t)ivn_len );
1232
+ ivn[ivn_len + 1] = '\0';
1222
1233
  rb_iv_set( obj, ivn, rb_ary_entry( vars, 1 ) );
1234
+ ALLOCV_END( ivn_v );
1223
1235
  return Qnil;
1224
1236
  }
1225
1237
 
@@ -0,0 +1,26 @@
1
+ require 'helper'
2
+
3
+ module Syck
4
+ # Both of these sized an `alloca` from the document. They are run on a Thread
5
+ # because a Ruby thread's stack is far smaller than the main stack, which is
6
+ # the shape a web or job worker actually has.
7
+ class TestLargeInput < Test::Unit::TestCase
8
+ SIZE = 4 * 1024 * 1024
9
+
10
+ def on_thread
11
+ Thread.new { yield }.value
12
+ end
13
+
14
+ def test_long_ivar_name
15
+ doc = "--- !ruby/object:Object\n" + ('n' * SIZE) + ": 1\n"
16
+ obj = on_thread { Syck.load(doc) }
17
+ assert_equal 1, obj.instance_variable_get("@#{'n' * SIZE}")
18
+ end
19
+
20
+ def test_long_compile_input
21
+ doc = "--- \n" + (0...(SIZE / 20)).map { |i| "k#{i}: v#{i}\n" }.join
22
+ bc = on_thread { Syck.compile(doc) }
23
+ assert_equal "D\n", bc[0, 2]
24
+ end
25
+ end
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syck
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi SHIBATA
@@ -107,6 +107,7 @@ files:
107
107
  - test/test_exception.rb
108
108
  - test/test_gc.rb
109
109
  - test/test_hash.rb
110
+ - test/test_large_input.rb
110
111
  - test/test_null.rb
111
112
  - test/test_omap.rb
112
113
  - test/test_set.rb
@@ -147,6 +148,7 @@ test_files:
147
148
  - test/test_exception.rb
148
149
  - test/test_gc.rb
149
150
  - test/test_hash.rb
151
+ - test/test_large_input.rb
150
152
  - test/test_null.rb
151
153
  - test/test_omap.rb
152
154
  - test/test_set.rb