Skip to content

fix: parse AsIntMap values as base 10 - #1026

Merged
rueian merged 1 commit into
redis:mainfrom
NotAFlightRisk:fix-asintmap-base-10
Sep 5, 2026
Merged

rueian merged 1 commit into
redis:mainfrom
NotAFlightRisk:fix-asintmap-base-10

Conversation

@NotAFlightRisk

@NotAFlightRisk NotAFlightRisk commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

AsIntSlice reads a value of "010" as 10, AsIntMap reads the same string as 8. It passes base 0 to strconv.ParseInt, so a leading zero gets treated as an octal prefix. "08" and "09" arent valid octal at all, so one of those anywhere in the reply fails the whole call with an invalid-syntax error and hands back a nil map.

Hash values are just whatever got writen into them, so a service or an import that zero-pads its numbers is enough to hit this through HGETALL.

Base 10 does change two other inputs: "0x1f" and "1_0" become errors rather than 31 and 10. That's what AsIntSlice already does with both of them, and I don't think Redis returns either shape as a map value, but it is a behaviour change.

"010" and "08" went into the existing AsIntMap subtest.


Note

Low Risk
Small, localized parsing fix in AsIntMap with a minor behavior change for non-decimal string literals; aligns with existing slice/scalar int parsing.

Overview
AsIntMap now parses string hash/map values with base 10 instead of strconv base 0, matching AsIntSlice and AsInt64.

That fixes wrong values for zero-padded decimals (e.g. "010" was octal 8, now 10) and avoids whole-map failures when a value like "08" or "09" is invalid in octal (common from HGETALL / stored string fields).

Tests cover "010" → 10 and "08" → 8. Values that only base 0 accepted (e.g. "0x1f", "1_0") now error instead of parsing—unlikely for typical Redis map payloads.

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

@rueian
rueian merged commit 2022f55 into redis:main Sep 5, 2026
29 checks passed
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