oj 3.16.17 → 3.17.3

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.
data/ext/oj/safe.h ADDED
@@ -0,0 +1,79 @@
1
+ #include <ruby.h>
2
+
3
+ #include "parser.h"
4
+ #include "usual.h"
5
+
6
+ #define SET_CONFIG(config_name) \
7
+ do { \
8
+ VALUE rb_##config_name = rb_hash_aref(options, config_name##_sym); \
9
+ \
10
+ if (RB_INTEGER_TYPE_P(rb_##config_name)) { \
11
+ safe->config_name = NUM2LONG(rb_##config_name); \
12
+ } else if (!NIL_P(rb_##config_name)) { \
13
+ rb_raise(rb_eArgError, "Incorrect value provided for `" #config_name "`"); \
14
+ } else { \
15
+ safe->config_name = Qnil; \
16
+ } \
17
+ } while (0);
18
+
19
+ #define DEFINE_DELEGATED_FUNCTION(function_name) \
20
+ static void safe_##function_name(ojParser p) { \
21
+ safe_T safe = (safe_T)p->ctx; \
22
+ \
23
+ safe->current_elements_count++; \
24
+ \
25
+ check_array_size(safe); \
26
+ check_max_total_elements(safe); \
27
+ \
28
+ safe->delegated_##function_name##_func(p); \
29
+ }
30
+
31
+ #define DEFINE_DELEGATED_OBJECT_FUNCTION(function_name) \
32
+ static void safe_##function_name##_key(ojParser p) { \
33
+ safe_T safe = (safe_T)p->ctx; \
34
+ \
35
+ safe->current_elements_count += 2; \
36
+ \
37
+ check_object_size(safe); \
38
+ check_max_total_elements(safe); \
39
+ \
40
+ safe->delegated_##function_name##_key_func(p); \
41
+ }
42
+
43
+ typedef struct _safe_S {
44
+ struct _usual usual;
45
+
46
+ long int max_hash_size;
47
+ long int max_array_size;
48
+ long int max_depth;
49
+ long int max_total_elements;
50
+ long int max_json_size_bytes;
51
+
52
+ long int current_hash_size;
53
+ long int current_array_size;
54
+ long int current_elements_count;
55
+
56
+ void (*delegated_start_func)(struct _ojParser *p);
57
+
58
+ // Array functions
59
+ void (*delegated_open_object_func)(struct _ojParser *p);
60
+ void (*delegated_open_array_func)(struct _ojParser *p);
61
+ void (*delegated_add_null_func)(struct _ojParser *p);
62
+ void (*delegated_add_true_func)(struct _ojParser *p);
63
+ void (*delegated_add_false_func)(struct _ojParser *p);
64
+ void (*delegated_add_int_func)(struct _ojParser *p);
65
+ void (*delegated_add_float_func)(struct _ojParser *p);
66
+ void (*delegated_add_big_func)(struct _ojParser *p);
67
+ void (*delegated_add_str_func)(struct _ojParser *p);
68
+
69
+ // Object functions
70
+ void (*delegated_open_object_key_func)(struct _ojParser *p);
71
+ void (*delegated_open_array_key_func)(struct _ojParser *p);
72
+ void (*delegated_add_null_key_func)(struct _ojParser *p);
73
+ void (*delegated_add_true_key_func)(struct _ojParser *p);
74
+ void (*delegated_add_false_key_func)(struct _ojParser *p);
75
+ void (*delegated_add_int_key_func)(struct _ojParser *p);
76
+ void (*delegated_add_float_key_func)(struct _ojParser *p);
77
+ void (*delegated_add_big_key_func)(struct _ojParser *p);
78
+ void (*delegated_add_str_key_func)(struct _ojParser *p);
79
+ } *safe_T;
data/ext/oj/sparse.c CHANGED
@@ -399,6 +399,7 @@ static void read_num(ParseInfo pi) {
399
399
  char c;
400
400
 
401
401
  reader_protect(&pi->rd);
402
+ ni.pi = pi;
402
403
  ni.i = 0;
403
404
  ni.num = 0;
404
405
  ni.div = 1;
@@ -549,6 +550,7 @@ static void read_nan(ParseInfo pi) {
549
550
  struct _numInfo ni;
550
551
  char c;
551
552
 
553
+ ni.pi = pi;
552
554
  ni.str = pi->rd.str;
553
555
  ni.i = 0;
554
556
  ni.num = 0;
@@ -745,6 +747,7 @@ void oj_sparse2(ParseInfo pi) {
745
747
  oj_set_error_at(pi, oj_parse_error_class, __FILE__, __LINE__, "expected NaN");
746
748
  return;
747
749
  }
750
+ ni.pi = pi;
748
751
  ni.str = pi->rd.str;
749
752
  ni.i = 0;
750
753
  ni.num = 0;
data/ext/oj/usual.c CHANGED
@@ -63,7 +63,7 @@ static VALUE form_attr(const char *str, size_t len) {
63
63
  memcpy(b + 1, str, len);
64
64
  b[len + 1] = '\0';
65
65
 
66
- id = rb_intern3(buf, len + 1, oj_utf8_encoding);
66
+ id = rb_intern3(b, len + 1, oj_utf8_encoding);
67
67
  OJ_R_FREE(b);
68
68
  return id;
69
69
  }
@@ -200,7 +200,10 @@ static void push_key(ojParser p) {
200
200
  d->ktail = d->khead + pos;
201
201
  d->kend = d->khead + cap;
202
202
  }
203
- d->ktail->len = klen;
203
+ if (32000 < klen) {
204
+ rb_raise(oj_json_parser_error_class, "Key too long. Keys are limited to 32,000 bytes.");
205
+ }
206
+ d->ktail->len = (int16_t)klen;
204
207
  if (klen < sizeof(d->ktail->buf)) {
205
208
  memcpy(d->ktail->buf, key, klen);
206
209
  d->ktail->buf[klen] = '\0';
@@ -608,12 +611,16 @@ static void dfree(ojParser p) {
608
611
  Usual d = (Usual)p->ctx;
609
612
 
610
613
  cache_free(d->str_cache);
614
+ d->str_cache = NULL;
611
615
  cache_free(d->attr_cache);
616
+ d->attr_cache = NULL;
612
617
  if (NULL != d->sym_cache) {
613
618
  cache_free(d->sym_cache);
619
+ d->sym_cache = NULL;
614
620
  }
615
621
  if (NULL != d->class_cache) {
616
622
  cache_free(d->class_cache);
623
+ d->class_cache = NULL;
617
624
  }
618
625
  OJ_R_FREE(d->vhead);
619
626
  OJ_R_FREE(d->chead);
@@ -640,6 +647,12 @@ static void mark(ojParser p) {
640
647
  if (NULL != d->class_cache) {
641
648
  cache_mark(d->class_cache);
642
649
  }
650
+ if (Qnil != d->hash_class) {
651
+ rb_gc_mark(d->hash_class);
652
+ }
653
+ if (Qnil != d->array_class) {
654
+ rb_gc_mark(d->array_class);
655
+ }
643
656
  for (vp = d->vhead; vp < d->vtail; vp++) {
644
657
  if (Qundef != *vp) {
645
658
  rb_gc_mark(*vp);
@@ -1050,10 +1063,10 @@ static VALUE opt_symbol_keys_set(ojParser p, VALUE value) {
1050
1063
  if (NULL != d->sym_cache) {
1051
1064
  cache_free(d->sym_cache);
1052
1065
  d->sym_cache = NULL;
1066
+ d->key_cache = NULL;
1053
1067
  }
1054
- if (!d->cache_keys) {
1055
- d->get_key = str_key;
1056
- }
1068
+ d->cache_keys = false;
1069
+ d->get_key = str_key;
1057
1070
  }
1058
1071
  return (NULL != d->sym_cache) ? Qtrue : Qfalse;
1059
1072
  }
data/ext/oj/wab.c CHANGED
@@ -19,7 +19,7 @@
19
19
  // Workaround in case INFINITY is not defined in math.h or if the OS is CentOS
20
20
  #define OJ_INFINITY (1.0 / 0.0)
21
21
 
22
- static char hex_chars[256] = "\
22
+ static char hex_chars[257] = "\
23
23
  ................................\
24
24
  ................xxxxxxxxxx......\
25
25
  .xxxxxx.........................\
data/lib/oj/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Oj
2
2
  # Current version of the module.
3
- VERSION = '3.16.17'
3
+ VERSION = '3.17.3'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oj
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.16.17
4
+ version: 3.17.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
@@ -158,6 +158,8 @@ files:
158
158
  - ext/oj/resolve.h
159
159
  - ext/oj/rxclass.c
160
160
  - ext/oj/rxclass.h
161
+ - ext/oj/safe.c
162
+ - ext/oj/safe.h
161
163
  - ext/oj/saj.c
162
164
  - ext/oj/saj2.c
163
165
  - ext/oj/saj2.h
@@ -229,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
231
  - !ruby/object:Gem::Version
230
232
  version: '0'
231
233
  requirements: []
232
- rubygems_version: 3.6.9
234
+ rubygems_version: 4.0.3
233
235
  specification_version: 4
234
236
  summary: A fast JSON parser and serializer.
235
237
  test_files: []