oj-safe 0.2.0 → 0.3.0
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 +4 -4
- data/ext/oj-safe/safe.c +23 -8
- data/lib/oj/safe/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 02c5aa00ec358c39f60b008cb8d0beeac926b5635eda855df53e98df453aa425
|
|
4
|
+
data.tar.gz: cd7db2bab94dc7286b1c9cedfa6e3fa2a6edf31ce67527530c7424d6e9006af2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9bc912c849561867cf7d780f9654e1c2a5df0605fea8e46eaa8d83417a5abe52d4cd9b3602a480ea7b52460cd5ad863f9a34ea852b97d18e269f04ae46908f1a
|
|
7
|
+
data.tar.gz: 3519be24f916efe79432313b1af5d37992d5ddfcfaee9bec3b5b07fb5bda33757e8ddc914b8349592bbdf76cc69c689bfe0509159120301baee701976ca45550
|
data/ext/oj-safe/safe.c
CHANGED
|
@@ -19,7 +19,11 @@ static VALUE max_hash_size_sym,
|
|
|
19
19
|
max_depth_sym,
|
|
20
20
|
max_total_elements_sym,
|
|
21
21
|
max_json_size_bytes_sym,
|
|
22
|
-
|
|
22
|
+
max_hash_size_error_class,
|
|
23
|
+
max_array_size_error_class,
|
|
24
|
+
max_depth_error_class,
|
|
25
|
+
max_total_elements_error_class,
|
|
26
|
+
max_json_size_error_class;
|
|
23
27
|
|
|
24
28
|
static ID parser_ivar_id,
|
|
25
29
|
parse_id,
|
|
@@ -74,7 +78,7 @@ static void check_object_size(safe_T safe) {
|
|
|
74
78
|
|
|
75
79
|
if(safe->max_hash_size > number_of_items_in_hash) return;
|
|
76
80
|
|
|
77
|
-
rb_raise(
|
|
81
|
+
rb_raise(max_hash_size_error_class, "Too many object items!");
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
static void check_array_size(safe_T safe) {
|
|
@@ -88,13 +92,13 @@ static void check_array_size(safe_T safe) {
|
|
|
88
92
|
|
|
89
93
|
if(safe->max_array_size > number_of_items_in_array) return;
|
|
90
94
|
|
|
91
|
-
rb_raise(
|
|
95
|
+
rb_raise(max_array_size_error_class, "Too many array items!");
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
static void check_max_depth(safe_T safe, ojParser p) {
|
|
95
99
|
if(safe->max_depth == 0 || safe->max_depth >= (p->depth + 1)) return;
|
|
96
100
|
|
|
97
|
-
rb_raise(
|
|
101
|
+
rb_raise(max_depth_error_class, "JSON is too deep!");
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
static void check_max_total_elements(safe_T safe) {
|
|
@@ -106,7 +110,7 @@ static void check_max_total_elements(safe_T safe) {
|
|
|
106
110
|
*/
|
|
107
111
|
if(safe->max_total_elements == 0 || safe->max_total_elements > safe->current_elements_count) return;
|
|
108
112
|
|
|
109
|
-
rb_raise(
|
|
113
|
+
rb_raise(max_total_elements_error_class, "Too many elements!");
|
|
110
114
|
}
|
|
111
115
|
|
|
112
116
|
static void check_json_size(VALUE parser, VALUE json) {
|
|
@@ -119,7 +123,7 @@ static void check_json_size(VALUE parser, VALUE json) {
|
|
|
119
123
|
|
|
120
124
|
if(safe->max_json_size_bytes == 0 || safe->max_json_size_bytes >= json_byte_size) return;
|
|
121
125
|
|
|
122
|
-
rb_raise(
|
|
126
|
+
rb_raise(max_json_size_error_class, "JSON payload is too big!");
|
|
123
127
|
}
|
|
124
128
|
|
|
125
129
|
static void safe_start(ojParser p) {
|
|
@@ -440,8 +444,19 @@ static VALUE rb_safe_parse(VALUE self, VALUE json) {
|
|
|
440
444
|
void Init_safe_ext(void) {
|
|
441
445
|
VALUE oj_module = rb_const_get(rb_cObject, rb_intern("Oj"));
|
|
442
446
|
VALUE safe_parser_class = rb_define_class_under(oj_module, "Safe", rb_cObject);
|
|
443
|
-
validation_error_class = rb_define_class_under(safe_parser_class, "ValidationError", rb_eRuntimeError);
|
|
444
|
-
|
|
447
|
+
VALUE validation_error_class = rb_define_class_under(safe_parser_class, "ValidationError", rb_eRuntimeError);
|
|
448
|
+
|
|
449
|
+
max_hash_size_error_class = rb_define_class_under(safe_parser_class, "HashSizeError", validation_error_class);
|
|
450
|
+
max_array_size_error_class = rb_define_class_under(safe_parser_class, "ArraySizeError", validation_error_class);
|
|
451
|
+
max_depth_error_class = rb_define_class_under(safe_parser_class, "DepthError", validation_error_class);
|
|
452
|
+
max_total_elements_error_class = rb_define_class_under(safe_parser_class, "TotalElementsError", validation_error_class);
|
|
453
|
+
max_json_size_error_class = rb_define_class_under(safe_parser_class, "PayloadSizeError", validation_error_class);
|
|
454
|
+
|
|
455
|
+
rb_gc_register_address(&max_hash_size_error_class);
|
|
456
|
+
rb_gc_register_address(&max_array_size_error_class);
|
|
457
|
+
rb_gc_register_address(&max_depth_error_class);
|
|
458
|
+
rb_gc_register_address(&max_total_elements_error_class);
|
|
459
|
+
rb_gc_register_address(&max_json_size_error_class);
|
|
445
460
|
|
|
446
461
|
max_hash_size_sym = ID2SYM(rb_intern("max_hash_size"));
|
|
447
462
|
max_array_size_sym = ID2SYM(rb_intern("max_array_size"));
|
data/lib/oj/safe/version.rb
CHANGED