Skip to content

[Bug] Heap-buffer-overflow in RapidJSON FullPrecision Parsing due to Integer Underflow #2405

Open

Description

@shuidaao

Summary

A heap-buffer-overflow (out-of-bounds read) vulnerability exists in RapidJSON v1.1.0 when parsing floating-point numbers with kParseFullPrecisionFlag. An integer underflow in decimalPosition leads to an out-of-bounds array access in GetCachedPowerByIndex().

Affected Versions

  • RapidJSON v1.1.0 (latest official release)
  • Likely earlier versions as well

Vulnerability Location

  • File: include/rapidjson/internal/diyfp.h
  • Function: GetCachedPowerByIndex()
  • Line: 223

Root Cause

During full-precision float parsing, the decimalPosition value underflows to 0xFFFFFFFFFFFFFFF0 (-16). This value is passed to StrtodDiyFp(), which computes an array index of 536870895. The kCachedPowers_F array only has about 87 elements, causing an out-of-bounds read.

PoC (46 bytes)

A 46-byte input: "1.1" followed by 192 zeros.

Document doc;
doc.Parse<kParseFullPrecisionFlag>("1.1" + std::string(192, '0'));

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions