json 2.21.0 → 2.21.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: 778c5ab5faa1a727c1c453ef34351537fd77dbb9a2f176abc15f6861391baab9
4
- data.tar.gz: 37f10916f3608596b4665564f61ee872bd647617048c0d593a4d2c917acc87df
3
+ metadata.gz: ea6afdf75f49e474e408c24daae4856891310979fbb10aa34ead66ad2fbf3321
4
+ data.tar.gz: 19eb129df23cde0ac607fa6ddf909d6ea5eaef0035b2180eea4c2c8a7a5c5ff0
5
5
  SHA512:
6
- metadata.gz: 36af0bdf70e46b374bb7d0ad209e946fffa367f2316a279249295aff233c4b187d69fa65753db29ffb20639e828896fd18e33e6060ecb0908f3a85b170c53443
7
- data.tar.gz: d148e9ef5ea0b428a562d422acb9357c8a061dada945eacb37b2c97e10c9c050253624881b16a4de547a7705011493db83a442afe230b828f9935a522c86c08d
6
+ metadata.gz: c2212cdac41569ebd41e83e6d1ea3324e944f6a8db0070a2805f2213da7341a05cc8eab4dc6d77852f30d31a8951f36d435fdb0aff647776eb8f42cee25113ef
7
+ data.tar.gz: b16fdb8a1f5384aa6e9064c7884c0f7ec96632bc2c1c6324cc2e902459e9ac94559ec691cf45dea30fc374fab74ce4e3a82f8bb9d0ec22e0ddd5357764076942
data/CHANGES.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
+ ### 2026-07-31 (2.21.2)
6
+
7
+ * Fix a use-after-free bug in `JSON::ResumableParser`. [GHSA-9hj4-r449-hfvc].
8
+
9
+ ### 2026-07-13 (2.21.1)
10
+
11
+ * Fix a compilation issue on Window and Microsoft Visual C++.
12
+
5
13
  ### 2026-07-12 (2.21.0)
6
14
 
7
15
  * `JSON.generate` now accept a `sort_keys` option, which takes either a boolean or a block.
@@ -15,22 +15,6 @@ have_func("rb_hash_new_capa", "ruby.h") # RUBY_VERSION >= 3.2
15
15
  have_func("rb_hash_bulk_insert", "ruby.h") # Missing on TruffleRuby
16
16
  have_func("ruby_xfree_sized", "ruby.h") # RUBY_VERSION >= 4.1
17
17
 
18
- def have_builtin_func(name, check_expr, opt = "", &b)
19
- checking_for checking_message(name.funcall_style, nil, opt) do
20
- if try_compile(<<SRC, opt, &b)
21
- int foo;
22
- int main() { #{check_expr}; return 0; }
23
- SRC
24
- $defs.push(format("-DHAVE_BUILTIN_%s", name.tr_cpp))
25
- true
26
- else
27
- false
28
- end
29
- end
30
- end
31
-
32
- have_builtin_func("__builtin_clzll", "__builtin_clzll(0)")
33
-
34
18
  if have_header("x86intrin.h")
35
19
  have_func("_lzcnt_u64", "x86intrin.h")
36
20
  end
@@ -46,6 +30,12 @@ end
46
30
 
47
31
  append_cflags("-std=c99")
48
32
 
33
+ # Disable function outlining on clang to prevent some of the repeated instructions
34
+ # in json_eat_whitespace being outlined into function calls.
35
+ # Note: This verifies '-mno-outline' is accepted as a valid compiler flag
36
+ # and will not pass it if unsupported.
37
+ append_cflags("-mno-outline")
38
+
49
39
  if enable_config('parser-use-simd', default=!ENV["JSON_DISABLE_SIMD"])
50
40
  load __dir__ + "/../simd/conf.rb"
51
41
  end
@@ -589,6 +589,8 @@ static inline char peek(JSON_ParserState *state)
589
589
 
590
590
  static void cursor_position(JSON_ParserState *state, long *line_out, long *column_out)
591
591
  {
592
+ JSON_ASSERT(!state->parser);
593
+ JSON_ASSERT(state->cursor);
592
594
  JSON_ASSERT(state->cursor <= state->end);
593
595
 
594
596
  // Redundant but helpful for hardening
@@ -621,10 +623,14 @@ static const unsigned int MAX_DEPRECATIONS = 5;
621
623
 
622
624
  static void emit_parse_warning(const char *message, JSON_ParserState *state)
623
625
  {
624
- long line, column;
625
- cursor_position(state, &line, &column);
626
-
627
- VALUE warning = rb_sprintf("%s at line %ld column %ld", message, line, column);
626
+ VALUE warning;
627
+ if (state->parser) { // line and columns can't be accurate in resumable
628
+ warning = rb_utf8_str_new_cstr(message);
629
+ } else {
630
+ long line, column;
631
+ cursor_position(state, &line, &column);
632
+ warning = rb_sprintf("%s at line %ld column %ld", message, line, column);
633
+ }
628
634
  rb_funcall(mJSON, rb_intern("deprecation_warning"), 1, warning);
629
635
  }
630
636
 
@@ -2566,6 +2572,7 @@ static VALUE cResumableParser_parse(VALUE self)
2566
2572
  if (eos(&parser->state)) {
2567
2573
  json_str_clear(parser->buffer);
2568
2574
  parser->buffer = Qfalse;
2575
+ parser->state.start = parser->state.cursor = parser->state.end = 0;
2569
2576
  }
2570
2577
  parser->in_use = false;
2571
2578
 
data/lib/json/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSON
4
- VERSION = '2.21.0'
4
+ VERSION = '2.21.2'
5
5
  end
data/lib/json.rb CHANGED
@@ -121,9 +121,11 @@ require 'json/common'
121
121
  # ====== Input Options
122
122
  #
123
123
  # Option +max_nesting+ (\Integer) specifies the maximum nesting depth allowed;
124
- # defaults to +100+; specify +false+ to disable depth checking.
124
+ # defaults to +100+;
125
+ # You can set it to +false+ to disable depth checking entirely, but that is dangerous
126
+ # when parsing untrusted input.
125
127
  #
126
- # With the default, +false+:
128
+ # With the default, +100+:
127
129
  # source = '[0, [1, [2, [3]]]]'
128
130
  # ruby = JSON.parse(source)
129
131
  # ruby # => [0, [1, [2, [3]]]]
@@ -384,6 +386,15 @@ require 'json/common'
384
386
  # # Raises JSON::NestingError (nesting of 2 is too deep):
385
387
  # JSON.generate(obj, max_nesting: 2)
386
388
  #
389
+ # With +false+:
390
+ # obj = []
391
+ # obj[0] = obj
392
+ # # Raises SystemStackError: stack level too deep
393
+ # JSON.generate(obj, max_nesting: false)
394
+ #
395
+ # Setting +max_nesting+ to +false+ can lead to a stackoverflow and may leave the program
396
+ # in an unrecoverable state. It is discouraged.
397
+ #
387
398
  # ====== Escaping Options
388
399
  #
389
400
  # Options +script_safe+ (boolean) specifies wether <tt>'\u2028'</tt>, <tt>'\u2029'</tt>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.21.0
4
+ version: 2.21.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  requirements: []
87
- rubygems_version: 4.0.12
87
+ rubygems_version: 4.0.16
88
88
  specification_version: 4
89
89
  summary: JSON Implementation for Ruby
90
90
  test_files: []