Skip to content

fix(cmd): reject out-of-range Int() on 32-bit - #4256

Merged
ndyakov merged 1 commit into
redis:masterfrom
b84330808:fix-cmd-int-32bit-range
Nov 2, 2026
Merged

ndyakov merged 1 commit into
redis:masterfrom
b84330808:fix-cmd-int-32bit-range

Conversation

@b84330808

@b84330808 b84330808 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

On 386 and arm, Cmd.Int() converts an integer reply with a plain int(...), so a value that doesn't fit wraps silently: :2147483648 comes back as -2147483648 with a nil error, and :9223372036854775807 as -1. The same number in a bulk string goes through strconv.Atoi and returns a range error.

This keeps the fast path when the value fits and otherwise returns exactly what Atoi gives for that number, so integer and bulk-string replies behave the same (like the float32 range check in toFloat32). Nothing changes on 64-bit.

TestCmdIntFromIntegerReplyOutOfRange compares both reply types around the int32 and int64 limits. I added it to the test-386 job's -run list, since that job only runs selected root tests. It fails with GOARCH=386 before the fix and passes after; it passes on amd64 either way (Go 1.27.3).


Note

Low Risk
Narrow fix to Cmd.Int() overflow handling on 32-bit only; no auth, networking, or 64-bit behavior changes.

Overview
On 386/arm, Cmd.Int() no longer silently truncates Redis integer replies (:…) that exceed int range. It keeps the fast path when int64(n) round-trips, and otherwise returns the same strconv.ErrRange behavior as a bulk-string reply via strconv.Atoi.

Adds TestCmdIntFromIntegerReplyOutOfRange to assert integer and bulk replies match around int32/int64 limits, and wires that test into the test-386 CI job’s selective -run list. 64-bit behavior is unchanged.

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

On 386 and arm, Cmd.Int truncated an integer reply that does not fit
in an int and returned it with a nil error, while the same number in a
bulk string gives Atoi's range error. Return that error for both.
@b84330808

Copy link
Copy Markdown
Contributor Author

I used Claude Code to write this change. Per AGENTS.md there's no AI-attribution line in the commit or the PR description, so I'm noting it here.

@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T12:35:30.175596Z 15f3834 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.

@ndyakov ndyakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me, thanks @b84330808

@ndyakov
ndyakov merged commit cfe0c86 into redis:master Nov 2, 2026
38 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