Skip to content

Accept '+' signs and underflowing exponents in RESP3 doubles - #1398

Open
waw666waw666 wants to merge 1 commit into
redis:masterfrom
waw666waw666:fix-resp3-double-plus-underflow
Open

waw666waw666 wants to merge 1 commit into
redis:masterfrom
waw666waw666:fix-resp3-double-plus-underflow

Conversation

@waw666waw666

@waw666waw666 waw666waw666 commented Nov 18, 2026 •

Copy link
Copy Markdown

Since #1328 switched RESP3 double parsing from strtod() to ffc, two kinds of valid doubles are rejected with a Bad double value protocol error, which puts the reader (and the connection) into an error state:

  • an explicit plus sign: ,+1.5\r\n
  • an exponent that underflows to zero: ,1e-400\r\n

The RESP3 spec allows both. Its grammar for doubles is ,[<+|->]<integral>[.<fractional>][<E|e>[sign]<exponent>]\r\n, so the sign can be +. And 1e-400 is a well-formed number that rounds to 0. Both parse fine with -DHIREDIS_FLOAT_STRTOD and in v1.4.x, so this is a regression in 1.5.0.

Repro:

redisReader *r = redisReaderCreate();
redisReaderFeed(r, ",+1.5\r\n", 7);
redisReaderGetReply(r, &reply);   /* REDIS_ERR, errstr "Bad double value" */

Cause

  • ffc_parse_options_default() does not set FFC_FORMAT_FLAG_ALLOW_LEADING_PLUS, so ffc stops at the +.
  • ffc returns FFC_OUTCOME_OUT_OF_RANGE for both overflow and underflow. On underflow it still stores a signed zero. The reader rejects every non-OK outcome, while strtod() returns 0 there and only overflow (±HUGE_VAL) was rejected, by the isfinite() check.

Fix

  • Parse with FFC_FORMAT_FLAG_NO_INFNAN | FFC_FORMAT_FLAG_ALLOW_LEADING_PLUS. Valkey's own ffc wrapper uses the same flag for the same reason (src/valkey_strtod.c).
  • Accept FFC_OUTCOME_OUT_OF_RANGE when the value is still finite. Underflow then yields ±0, as with strtod(). Overflow yields ±inf, so the existing isfinite() check still rejects it.

I diffed the ffc build against the HIREDIS_FLOAT_STRTOD build on ~110k inputs (random digit/sign/exponent strings plus formatted doubles over the whole range). Before this change there were 511 accept/value mismatches, all of them a leading + or an underflow. After it, the only differences left are the intended stricter rejections of leading whitespace and hex floats (" 1", 0x10, 0x1p3).

Tests

  • Parses RESP3 double edge magnitudes bit-exactly: added +1.5, +0, +3E+2, 1e-400, -1e-400 (sign bit checked) and 2e-324.
  • Rejects malformed RESP3 doubles: added +-1, ++1, +inf, 1e400 and -1e400, so overflow and malformed signs stay errors.

The reader tests pass with both the default ffc build and -DHIREDIS_FLOAT_STRTOD. Without the read.c change, the edge-magnitude test fails.


Note

Medium Risk
Touches core RESP3 protocol parsing for doubles; behavior change restores spec compliance but affects every connection that receives such replies.

Overview
Fixes a 1.5.0 regression where the ffc-based RESP3 double parser rejected values that the spec and older strtod builds accepted, leaving the reader in a Bad double value error state.

The ffc path now parses with FFC_FORMAT_FLAG_ALLOW_LEADING_PLUS so tokens like ,+1.5 are valid, and it treats FFC_OUTCOME_OUT_OF_RANGE like strtod when the parsed value is still finite (underflow to ±0), while isfinite() continues to reject overflow to infinity. Malformed signs and overflow cases stay errors.

Reader tests add bit-exact cases for + signs, underflow to signed zero, and rejections for +-1, ++1, +inf, and ±1e400.

Reviewed by Cursor Bugbot for commit 3d6d183. Bugbot is set up for automated code reviews on this repo. Configure here.

Since RESP3 doubles are parsed with ffc, a double with an explicit plus
sign (",+1.5") or an exponent that underflows to zero (",1e-400") is
reported as a "Bad double value" protocol error, although the RESP3
grammar allows both and the strtod path (HIREDIS_FLOAT_STRTOD) accepts
them.

Enable ffc's ALLOW_LEADING_PLUS flag, and accept FFC_OUTCOME_OUT_OF_RANGE
when the value is still finite: ffc returns a signed zero on underflow
and an infinity on overflow, so overflow keeps being rejected by the
isfinite check exactly as before.
@github-actions github-actions Bot added the bug label Nov 18, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T05:18:30.105436Z 3d6d183 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant