Repository navigation
Accept '+' signs and underflowing exponents in RESP3 doubles - #1398
Open
waw666waw666 wants to merge 1 commit into
Open
waw666waw666 wants to merge 1 commit into
waw666waw666 wants to merge 1 commit into
Conversation
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.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since #1328 switched RESP3 double parsing from
strtod()to ffc, two kinds of valid doubles are rejected with aBad double valueprotocol error, which puts the reader (and the connection) into an error state:,+1.5\r\n,1e-400\r\nThe RESP3 spec allows both. Its grammar for doubles is
,[<+|->]<integral>[.<fractional>][<E|e>[sign]<exponent>]\r\n, so the sign can be+. And1e-400is a well-formed number that rounds to 0. Both parse fine with-DHIREDIS_FLOAT_STRTODand in v1.4.x, so this is a regression in 1.5.0.Repro:
Cause
ffc_parse_options_default()does not setFFC_FORMAT_FLAG_ALLOW_LEADING_PLUS, so ffc stops at the+.FFC_OUTCOME_OUT_OF_RANGEfor both overflow and underflow. On underflow it still stores a signed zero. The reader rejects every non-OK outcome, whilestrtod()returns 0 there and only overflow (±HUGE_VAL) was rejected, by theisfinite()check.Fix
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).FFC_OUTCOME_OUT_OF_RANGEwhen the value is still finite. Underflow then yields ±0, as withstrtod(). Overflow yields ±inf, so the existingisfinite()check still rejects it.I diffed the ffc build against the
HIREDIS_FLOAT_STRTODbuild 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) and2e-324.Rejects malformed RESP3 doubles: added+-1,++1,+inf,1e400and-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
strtodbuilds accepted, leaving the reader in a Bad double value error state.The ffc path now parses with
FFC_FORMAT_FLAG_ALLOW_LEADING_PLUSso tokens like,+1.5are valid, and it treatsFFC_OUTCOME_OUT_OF_RANGElikestrtodwhen the parsed value is still finite (underflow to ±0), whileisfinite()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.