Revert "Fix Python VarIntCoder OverflowError on uint64 values"#39218
Revert "Fix Python VarIntCoder OverflowError on uint64 values"#39218Abacn wants to merge 1 commit into
Conversation
This reverts commit e87f50e.
|
R: @jrmccluskey |
|
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request reverts a previous change that aimed to fix Python VarIntCoder OverflowError on uint64 values. The reversion is necessary due to an identified performance regression caused by the previous implementation. The changes effectively restore the previous behavior where the coder is limited to 64-bit signed integers. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request simplifies VarIntCoderImpl by removing the folding of uint64 values into signed int64 integers, restricting the coder strictly to 64-bit signed integers. Feedback suggests wrapping the type cast in encode with a try...except block to prevent Cython from raising an unhandled OverflowError before reaching the custom error handling. Additionally, it is recommended to add a test case verifying that out-of-range values correctly raise an OverflowError to maintain test coverage after the removal of test_varint_coder_uint64.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| def encode(self, value): | ||
| # Compare as a Python object: a uint64 value overflows the int64_t cast | ||
| # the compiled fast path used to do here. Non-small values (including | ||
| # uint64) fall through to encode_to_stream, which folds them. | ||
| if 0 <= value < len(small_ints): | ||
| return small_ints[value] | ||
| ivalue = value # type cast | ||
| if 0 <= ivalue < len(small_ints): | ||
| return small_ints[ivalue] | ||
| return StreamCoderImpl.encode(self, value) |
There was a problem hiding this comment.
In Cython compiled mode, ivalue is declared as int64_t in .pxd. The assignment ivalue = value performs a type cast. If value is an integer that overflows the 64-bit signed integer range, this assignment will raise an OverflowError immediately.
This bypasses the fallback to StreamCoderImpl.encode(self, value) and the custom OverflowError handling in encode_to_stream (lines 1048-1053), which is designed to provide a helpful error message explaining the 64-bit signed integer limit. Instead, the user receives a generic Cython OverflowError.
Wrapping the type cast and small integer check in a try...except OverflowError block allows the overflow to be caught and safely delegated to StreamCoderImpl.encode, which will then raise the descriptive error message.
def encode(self, value):
try:
ivalue = value # type cast
if 0 <= ivalue < len(small_ints):
return small_ints[ivalue]
except OverflowError:
pass
return StreamCoderImpl.encode(self, value)| with self.assertRaises(OverflowError): | ||
| coder.encode(v) | ||
|
|
||
| def test_varint32_coder(self): |
There was a problem hiding this comment.
Since test_varint_coder_uint64 is being removed, we should ensure that we still have test coverage verifying that values outside the supported 64-bit signed integer range (such as 1 << 63, 1 << 64, and -(1 << 63) - 1) correctly raise OverflowError.
| def test_varint32_coder(self): | |
| def test_varint_coder_overflow(self): | |
| coder = coders.VarIntCoder() | |
| for v in [1 << 63, 1 << 64, -(1 << 63) - 1]: | |
| with self.assertRaises(OverflowError): | |
| coder.encode(v) | |
| def test_varint32_coder(self): |
Reverts #39047 due to performance regression
encoding values>INT_MAX with varint coder is undefined behavior. Guarding it at the cost of performance degradation isn't preferred
more context: #39047 (comment)
closes #39216