2.18.3 still ships the CVE-2026-54696 heap overflow (Ruby 4.0.10 bundles it) — is a 2.18.4 backport planned?
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 42/100
Rechercherichtung
Start with ext/json/ext/fbuffer/fbuffer.h and the fbuffer_do_inc_capa logic described in the issue, then review the cited upstream fix in commit 996bac686d. Reproduce the overflow with the provided StringIO example and verify a candidate backport with the test/json suite. Done means the IO generator no longer overflows and the 2.18.x maintenance and release path is clarified.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
CVE-2026-54696 (heap buffer overflow in the JSON generator when streaming to
an IO) is fixed only in 2.19.9, but 2.18.3 still contains the vulnerable
code — and 2.18.3 was released on 2026-11-13, i.e. after 2.19.9
(2026-06-11).
Consequence: Ruby 4.0.10 ships json 2.18.3 (ext/json/fbuffer/fbuffer.h in
ruby_4_0 is byte-identical to the 2.18.3 gem, sha256
21441869ea8e...a7d6), so the current stable Ruby is vulnerable to a
1-byte heap overflow that aborts the process.
Is 2.18.x still maintained? If yes, could a 2.18.4 be cut with the fix?
If not, that's fine — Ruby just needs to sync ext/json to 2.19.9+ for 4.0.x,
but I'd like to know which way to push.
Reproducer
# json_54696_poc.rb
require "json"
require "stringio"
io = StringIO.new
JSON.dump([1] * 7 + ["a" * 16_380], io) # 1 byte past the 16 383-byte buffer
puts "survived: #{io.string.bytesize} bytes"
$ gem install json -v 2.18.3
$ ruby json_54696_poc.rb
malloc(): corrupted top size
Aborted (core dumped) # exit 134
$ gem install json -v 2.19.9
$ ruby json_54696_poc.rb
survived: 16398 bytes
No sanitizer needed; n=7 (the smallest overflow, 1 byte) is already enough to
corrupt the malloc chunk header and abort. JSON::State#generate(obj, io) is
affected the same way; JSON.generate(obj) without an IO is not.
On Ruby 4.0.10 with a full ASan build of the tree:
==378931==ERROR: AddressSanitizer: heap-buffer-overflow
WRITE of size 16368 at 0x5290000221ff thread T0
#1 ruby_nonempty_memcpy
#2 fbuffer_append_reserved ext/json/fbuffer/fbuffer.h:136
#5 search_flush ext/json/generator/generator.c:142
#6 copy_remaining_bytes ext/json/generator/generator.c:294
#7 search_escape_basic_sse2 ext/json/generator/generator.c:486
#8 convert_UTF8_to_JSON ext/json/generator/generator.c:234
#9 raw_generate_json_string ext/json/generator/generator.c:1141
#10 generate_json_array ext/json/generator/generator.c:1319
0x5290000221ff is located 0 bytes to the right of 16383-byte region
Cause
In 2.18.3 ext/json/ext/fbuffer/fbuffer.h:
static void fbuffer_do_inc_capa(FBuffer *fb, unsigned long requested)
{
if (RB_UNLIKELY(fb->io)) {
if (fb->capa < FBUFFER_IO_BUFFER_SIZE) {
fbuffer_realloc(fb, FBUFFER_IO_BUFFER_SIZE); /* 512 -> 16383, len stays 16 */
} else {
fbuffer_flush(fb);
}
if (RB_LIKELY(requested < fb->capa)) { /* ignores fb->len */
return;
}
}
...
The buffer starts with the 512-byte stack buffer; the first growth reallocates
to 16 383 bytes without flushing, and the early return compares requested
with the total capacity instead of the remaining room. The SIMD tail of a
long string is passed as one 16 368-byte chunk, so with 16 bytes already in
the buffer 16 + 16368 > 16383.
Fixes tested
Minimal backport for 2.18.x (one line, keeps the existing structure):
- if (RB_LIKELY(requested < fb->capa)) {
+ if (RB_LIKELY(requested <= fb->capa - fb->len)) {
return;
}
Upstream design (what 2.19.9 has, and ruby/ruby master):
fb->capa != 0 → flush, then compare; grow capacity from requested + fb->len
(json commit 996bac686d / ruby/ruby 9ac37cd626).
I tested both against Ruby 4.0.10 sources (i.e. the 2.18.3 code) on a full
ASan build:
- PoCs above + a sweep of 32 (length 16 350…16 400 × padding 7…240)
combinations: pre-fix ASanWRITE of size 16336on the first one; both
fixes clean,sweep ok: 32 combinations. - 3.96M fuzz iterations on the one-line fix, 7 005 IO-generator iterations on
the upstream-style backport (strings near 16 KB, escapes/UTF-8,StringIO
andFiletargets): no ASan reports. test/jsonon the patched tree: 224 tests, 3 147 assertions, 0 failures.
I can send either variant as a PR to the 2.18.3 tag (or a patch file) if you
prefer — just say which one.
Changelog nit
CHANGES.md in 2.18.3 lists the format-string fix (GHSA-3m6g-2423-7cp3)
under the 2026-11-02 (2.18.2) heading, but the 2.18.2 tarball does not
contain it — JSON.parse('{"%s%s%s%s":1,"%s%s%s%s":2}', allow_duplicate_key: false)
still segfaults on 2.18.2 and only 2.18.3 raises JSON::ParserError
(filed rubysec/ruby-advisory-db#1344 to add 2.18.3 as a patched version).
Probably worth moving that entry to the 2.18.3 section.
- Vorherrschende Sprache
- Ruby
- Sterne
- 787
- Forks
- 392
- Ø Merge
- 6 Std. 4 Min.
- Gemergte PRs (30 T.)
- 22
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus ruby/json
-
Audit excluded tests on JRuby and address differencesEvtl. vergeben @ojuschugh1 hat das vor 5 Tagen übernommen. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
ruby/json#1123 · 5 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
ruby/json#1041 · 7 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Output formatting differences between jRuby 10.0.0.1 and Ruby 3.4 when converting Float to JSON.Evtl. vergeben @headius hat das vor 459 Tagen übernommen. Offenjruby
ruby/json#817 · 3 Kommentare · 1 Reaktion · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Don't cache JRuby runtime in static fieldsEvtl. wieder frei @headius hat das vor 736 Tagen übernommen, und es ist kein Pull Request offen. Offenjruby
ruby/json#707 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
new feature
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
ruby/json#252 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
open-feature/ruby-sdk-contrib#340 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
zold-io/wts.zold.io#651 ·
Maintainer antworten meist innerhalb von 1 Tag
-
good first issue help wanted
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 87/100
erkamyaman/rust-anything#788 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 74/100
TheOdinProject/curriculum#31579 ·
Maintainer antworten meist innerhalb von 1 Tag