Skip to content

fix(geo): validate positive COUNT arguments#3459

Open
jihuayu wants to merge 5 commits intoapache:unstablefrom
jihuayu:codex/count-0
Open

fix(geo): validate positive COUNT arguments#3459
jihuayu wants to merge 5 commits intoapache:unstablefrom
jihuayu:codex/count-0

Conversation

@jihuayu
Copy link
Copy Markdown
Member

@jihuayu jihuayu commented Apr 22, 2026

The original code overlooked the requirement for COUNT to be a positive integer, resulting in an inconsistency with the Redis protocol.

I have modified the implementation to refactor the special case where count == 0 is treated as if no count were provided, ensuring code cleanliness and logical transparency.

Assisted-by: Codex

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens Geo command argument parsing by rejecting non-positive COUNT values and refactors the internal “count specified” logic to no longer rely on count == 0.

Changes:

  • Added ParseCount and has_count plumbing for GEORADIUS* and GEOSEARCH* command parsing.
  • Updated redis::Geo APIs (Radius*, Search*) to accept has_count separately from count, and adjusted store logic accordingly.
  • Added/updated unit tests (Go and C++) to cover COUNT <= 0 parse errors and updated method signatures.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/gocase/unit/geo/geo_test.go Adds Go-level coverage asserting COUNT of 0 / -1 returns a parse error across geo commands.
tests/cppunit/types/geo_test.cc Updates C++ unit tests to match the new Geo API signatures.
src/types/redis_geo.h Updates Geo public method signatures to include has_count and use size_t for count.
src/types/redis_geo.cc Threads has_count through to store logic; refactors stored-result limiting loop.
src/commands/cmd_geo.cc Implements ParseCount, switches geo commands to explicit has_count tracking, and enforces COUNT > 0.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/commands/cmd_geo.cc Outdated
Comment thread src/types/redis_geo.h
Comment thread src/commands/cmd_geo.cc Outdated
return Status::OK();
}

auto unsigned_count = ParseInt<size_t>(raw_count, 10);
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.

didn't get why you parse it twice.

Copy link
Copy Markdown
Member Author

@jihuayu jihuayu Apr 22, 2026

Choose a reason for hiding this comment

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

Ohhh. I got what your means. I will change it latter.

Since we need to check if it's a positive number, size_t is always non-negative.

Perhaps we could use a helper function to determine if it's a positive number? It might make the logic clearer.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Copy Markdown
Member

@PragmaTwice PragmaTwice left a comment

Choose a reason for hiding this comment

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

could you put why you make this change instead of what you change in PR description?

@jihuayu
Copy link
Copy Markdown
Member Author

jihuayu commented Apr 22, 2026

could you put why you make this change instead of what you change in PR description?

could you put why you make this change instead of what you change in PR description?

Done. Thanks!

@sonarqubecloud
Copy link
Copy Markdown

@jihuayu jihuayu requested a review from PragmaTwice April 23, 2026 01:12
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.

3 participants