CVE-2026-35201: Rdiscount Rdiscount Has An Out-of-bounds Read Vulnerability

MODERATE
Advisory Identifier: GHSA-6r34-94wq-jhrc
CVSS 5.9
CWE-125
Published
Advisory Summary

CVE-2026-35201 is a MODERATE (CVSS 5.9) rdiscount has an out-of-bounds read vulnerability (CWE-125: Out-of-bounds Read) affecting Rdiscount libraries in the RubyGems ecosystem. The issue involves rdiscount has an out-of-bounds read. Remediation is available by upgrading affected packages to version 2.2.7.4.

CVE-2026-35201 at a Glance

CVE Identifier CVE-2026-35201
GHSA Identifier GHSA-6r34-94wq-jhrc
Severity MODERATE
CVSS v3.1 Base Score 5.9
CWE Classification CWE-125: Out-of-bounds Read
Affected Product Rdiscount
Package Ecosystem RubyGems
Published Date
Last Updated

Security Impact

CVSS: 5.9

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity None (I:N)
Availability High (A:H)

How to Fix CVE-2026-35201

To remediate this vulnerability, upgrade all affected Rdiscount dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

rdiscount fixed: 2.2.7.4
Upgrade rdiscount to 2.2.7.4
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for rdiscount

How to Check if You Are Affected

To determine whether your application is affected by CVE-2026-35201, inspect your project dependencies for Rdiscount:

inspect dependencies for rdiscount

Analyze the terminal output to locate any version of Rdiscount in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.2.7.4), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-125: Out-of-bounds Read, where the product reads data past the end, or before the beginning, of the intended buffer. In Rdiscount, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary A signed length truncation bug causes an out-of-bounds read in the default Markdown parse path. Inputs larger than `INT_MAX` are truncated to a signed `int` before entering the native parser, allowing the parser to read past the end of the supplied buffer and crash the process ### Details In both public entry points: - `ext/rdiscount.c:97` - `ext/rdiscount.c:136` `RSTRING_LEN(text)` is passed directly into `mkd_string()`: ```c MMIOT *doc = mkd_string(RSTRING_PTR(text), RSTRING_LEN(text), flags); ``` `mkd_string()` accepts `int len`: - `ext/mkdio.c:174` ```c Document * mkd_string(const char *buf, int len, mkd_flag_t flags) { struct string_stream about; about.data = buf; about.size = len; return populate((getc_func)__mkd_io_strget, &about, flags & INPUT_MASK); } ``` The parser stores the remaining input length in a signed `int`: - `ext/markdown.h:205` ```c struct string_stream { const char *data; int size; }; ``` The read loop stops only when `size == 0`: - `ext/mkdio.c:161` ```c int __mkd_io_strget(struct string_stream *in) { if ( !in->size ) return EOF; --(in->size); return *(in->data)++; } ``` If the Ruby string length exceeds `INT_MAX`, the value can truncate to a negative `int`. In that state, the parser continues incrementing `data` and reading past the end of the original Ruby string, causing an out-of-bounds read and native crash. Affected APIs: - `RDiscount.new(input).to_html` - `RDiscount.new(input).toc_content` ### PoC Crash via `to_html`: ```sh RUBYLIB=lib:ext ruby -e 'require "rdiscount"; n=2_200_000_000; s = "a" * n; warn "built=#{s.bytesize}"; RDiscount.new(s).to_html"' ``` result: - `built=2200000000` - Ruby terminates with `[BUG] Segmentation fault` - top control frame: `CFUNC :to_html` same result with `toc_content` ### Impact This is an out-of-bounds read with the main issue being reliable denial-of-service. Impacted is limited to deployments parses attacker-controlled Markdown and permits multi-GB inputs. ### Fix just add a checked length guard before the `mkd_string()` call in both public entry points: - `ext/rdiscount.c:97` - `ext/rdiscount.c:136` ex: ```c VALUE text = rb_funcall(self, rb_intern("text"), 0); long text_len = RSTRING_LEN(text); VALUE buf = rb_str_buf_new(1024); Check_Type(text, T_STRING); if (text_len > INT_MAX) { rb_raise(rb_eArgError, "markdown input too large"); } MMIOT *doc = mkd_string(RSTRING_PTR(text), (int)text_len, flags); ``` The same guard should be applied in `rb_rdiscount_toc_content()` before its `mkd_string()` call.

CVE-2026-35201 Affected Rdiscount Versions

1 component(s)
Fixed Versions:
2.2.7.4
Product / Package Ecosystem Affected Versions Fixed Version
rdiscount
RubyGems
≥ 1.3.1.1
< 2.2.7.4
2.2.7.4

References

Frequently Asked Questions

What is CVE-2026-35201?
CVE-2026-35201 is a security vulnerability in Rdiscount involving rdiscount has an Out-of-bounds Read under CWE-125: Out-of-bounds Read.
Which Rdiscount versions are affected?
Affected versions include releases prior to 2.2.7.4 across affected packages: rdiscount.
What version fixes CVE-2026-35201?
Upgrading to 2.2.7.4 (or the latest patched release for your respective branch) resolves the vulnerability.
Is rdiscount affected?
Yes, rdiscount is affected in releases prior to 2.2.7.4. Upgrade your dependency to 2.2.7.4 or later.
What is the CVSS score of CVE-2026-35201?
CVE-2026-35201 has a CVSS v3.1 base score of 5.9 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H.
What CWE is associated with CVE-2026-35201?
CVE-2026-35201 is classified under CWE-125: Out-of-bounds Read (The product reads data past the end, or before the beginning, of the intended buffer.).
How can I check RubyGems dependencies for CVE-2026-35201?
Run the dependency tree command: 'inspect dependencies for rdiscount'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-6r34-94wq-jhrc",
  "modified" : "2026-05-13T16:20:38Z",
  "published" : "2026-04-06T17:53:59Z",
  "aliases" : [ "CVE-2026-35201" ],
  "summary" : "rdiscount has an Out-of-bounds Read",
  "details" : "### Summary\n\nA signed length truncation bug causes an out-of-bounds read in the default Markdown parse path. Inputs larger than `INT_MAX` are truncated to a signed `int` before entering the native parser, allowing the parser to read past the end of the supplied buffer and crash the process\n\n### Details\n\nIn both public entry points:\n\n- `ext/rdiscount.c:97`\n- `ext/rdiscount.c:136`\n\n`RSTRING_LEN(text)` is passed directly into `mkd_string()`:\n\n```c\nMMIOT *doc = mkd_string(RSTRING_PTR(text), RSTRING_LEN(text), flags);\n```\n\n`mkd_string()` accepts `int len`:\n\n- `ext/mkdio.c:174`\n\n```c\nDocument * mkd_string(const char *buf, int len, mkd_flag_t flags)\n{\n    struct string_stream about;\n\n    about.data = buf;\n    about.size = len;\n\n    return populate((getc_func)__mkd_io_strget, &about, flags & INPUT_MASK);\n}\n```\n\nThe parser stores the remaining input length in a signed `int`:\n\n- `ext/markdown.h:205`\n\n```c\nstruct string_stream {\n    const char *data;\n    int   size;\n};\n```\n\nThe read loop stops only when `size == 0`:\n\n- `ext/mkdio.c:161`\n\n```c\nint __mkd_io_strget(struct string_stream *in)\n{\n    if ( !in->size ) return EOF;\n\n    --(in->size);\n\n    return *(in->data)++;\n}\n```\n\nIf the Ruby string length exceeds `INT_MAX`, the value can truncate to a negative `int`. In that state, the parser continues incrementing `data` and reading past the end of the original Ruby string, causing an out-of-bounds read and native crash.\n\nAffected APIs:\n\n- `RDiscount.new(input).to_html`\n- `RDiscount.new(input).toc_content`\n\n### PoC\n\nCrash via `to_html`:\n\n```sh\nRUBYLIB=lib:ext ruby -e 'require \"rdiscount\"; n=2_200_000_000; s = \"a\" * n; warn \"built=#{s.bytesize}\"; RDiscount.new(s).to_html\"'\n```\nresult:\n\n- `built=2200000000`\n- Ruby terminates with `[BUG] Segmentation fault`\n- top control frame: `CFUNC :to_html`\n\nsame result with `toc_content`\n\n### Impact\n\nThis is an out-of-bounds read with the main issue being reliable denial-of-service. Impacted is limited to deployments parses attacker-controlled Markdown and permits multi-GB inputs.\n\n### Fix\n\njust add a checked length guard before the `mkd_string()` call in both public entry points:\n\n- `ext/rdiscount.c:97`\n- `ext/rdiscount.c:136`\nex: \n```c\nVALUE text = rb_funcall(self, rb_intern(\"text\"), 0);\nlong text_len = RSTRING_LEN(text);\nVALUE buf = rb_str_buf_new(1024);\nCheck_Type(text, T_STRING);\n\nif (text_len > INT_MAX) {\n    rb_raise(rb_eArgError, \"markdown input too large\");\n}\n\nMMIOT *doc = mkd_string(RSTRING_PTR(text), (int)text_len, flags);\n```\n\nThe same guard should be applied in `rb_rdiscount_toc_content()` before its `mkd_string()` call.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "rdiscount"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "1.3.1.1"
      }, {
        "fixed" : "2.2.7.4"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/davidfstr/rdiscount/security/advisories/GHSA-6r34-94wq-jhrc"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-35201"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/davidfstr/rdiscount/commit/b1a16445e92e0d12c07594dedcdc56f80b317761"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/davidfstr/rdiscount"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/rubysec/ruby-advisory-db/blob/master/gems/rdiscount/CVE-2026-35201.yml"
  }, {
    "type" : "WEB",
    "url" : "http://github.com/davidfstr/rdiscount/releases/tag/2.2.7.4"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-125" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-04-06T17:53:59Z",
    "nvd_published_at" : "2026-04-06T20:16:27Z"
  }
}