Skip to content

fix redis: use FromString for double reply values - #1297

Closed
netliomax25-code wants to merge 1 commit into
userver-framework:developfrom
netliomax25-code:redis-reply-double-parse
Closed

fix redis: use FromString for double reply values#1297
netliomax25-code wants to merge 1 commit into
userver-framework:developfrom
netliomax25-code:redis-reply-double-parse

Conversation

@netliomax25-code

Copy link
Copy Markdown
Contributor
  1. Parse(..., To<double>) converts floating-point reply values (ZSCORE, HINCRBYFLOAT, ZADD ... INCR) with std::stod, which respects the process LC_NUMERIC and keeps only the valid numeric prefix of the string.
  2. under a comma-decimal locale "3.14" parses as 3.0, and a reply like "3.14x" parses as 3.14 with the trailing bytes silently dropped, so a compromised or MITM'd server can return a corrupted value.

Switched to utils::FromString<double>, matching the geo parser at line 58 and the score parser at line 166 in this file: it is locale-independent and rejects trailing junk, while numbers, scientific notation, and inf/-inf still parse the same. Added a regression test for the trailing-junk case along with valid and infinite values.

@apolukhin

Copy link
Copy Markdown
Member

LGTM

@robot-magpie

robot-magpie Bot commented Jul 27, 2026

Copy link
Copy Markdown

Many thanks for the PR! @apolukhin is now importing your pull request into our internal upstream repository.

@robot-magpie

robot-magpie Bot commented Jul 28, 2026

Copy link
Copy Markdown

✅ This pull request is being closed because it has been successfully merged into our internal monorepository.
Your changes will be pushed to this repository soon. Thank you for your contribution!

@robot-magpie robot-magpie Bot closed this Jul 28, 2026
robot-piglet pushed a commit that referenced this pull request Jul 28, 2026
1. `Parse(..., To<double>)` converts floating-point reply values (`ZSCORE`, `HINCRBYFLOAT`, `ZADD ... INCR`) with `std::stod`, which respects the process `LC_NUMERIC` and keeps only the valid numeric prefix of the string.
2. under a comma-decimal locale `"3.14"` parses as `3.0`, and a reply like `"3.14x"` parses as `3.14` with the trailing bytes silently dropped, so a compromised or MITM'd server can return a corrupted value.

Switched to `utils::FromString<double>`, matching the geo parser at line 58 and the score parser at line 166 in this file: it is locale-independent and rejects trailing junk, while numbers, scientific notation, and `inf`/`-inf` still parse the same. Added a regression test for the trailing-junk case along with valid and infinite values.

---

Pull Request resolved: #1297

Co-authored-by: antoshkka <antoshkka@userver.tech>
commit_hash:e5b7997828ad3c0a5d02d03bf9a62d907405f3bc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants