Skip to content

fix(eap): Cast OOB ints to str#104787

Merged
thetruecpaul merged 1 commit intomasterfrom
cpaul/121125/eapmaxintfix
Dec 11, 2025
Merged

fix(eap): Cast OOB ints to str#104787
thetruecpaul merged 1 commit intomasterfrom
cpaul/121125/eapmaxintfix

Conversation

@thetruecpaul
Copy link
Copy Markdown
Contributor

We're seeing an error (https://sentry.sentry.io/issues/7087482631/) where we're trying to encode ints that are OOB of the int64 max.

In this edge case, let's cast to str. (Better than dropping the data and fixes the problem for now. If it's a problem later we can look into it again.)

@thetruecpaul thetruecpaul requested a review from a team December 11, 2025 18:36
@thetruecpaul thetruecpaul requested a review from a team as a code owner December 11, 2025 18:36
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Dec 11, 2025
We're seeing an error (https://sentry.sentry.io/issues/7087482631/) where we're trying to encode ints that are OOB of the `int64` max.

In this edge case, let's cast to `str`. (Better than dropping the data and fixes the problem for now. If it's a problem later we can look into it again.)
@thetruecpaul thetruecpaul force-pushed the cpaul/121125/eapmaxintfix branch from 8617602 to 8c900f1 Compare December 11, 2025 18:39
elif isinstance(value, int):
# int_value is a signed int64, so it has a range of valid values.
# if value doesn't fit into an int64, cast it to string.
if abs(value) >= (2**63):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The boundary check abs(value) >= (2**63) incorrectly converts the minimum valid int64 value, -2**63, to a string due to an off-by-one error.
Severity: HIGH | Confidence: High

🔍 Detailed Analysis

The boundary check at line 47, if abs(value) >= (2**63):, is intended to handle integers outside the valid int64 range. However, it contains an off-by-one error. The valid range for a signed 64-bit integer is [-2**63, 2**63 - 1]. When the input value is exactly -2**63 (the minimum valid value), abs(value) becomes 2**63, causing the condition to evaluate to True. This incorrectly triggers the conversion of a valid int64 value to a string, which can lead to data type mismatches and processing errors in downstream systems that expect an integer.

💡 Suggested Fix

Modify the boundary check to correctly handle the full int64 range. The condition should be if value < -(2**63) or value >= 2**63:. This ensures that the minimum valid value, -2**63, is correctly identified as an integer and not converted to a string.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/sentry/eventstream/item_helpers.py#L47

Potential issue: The boundary check at line 47, `if abs(value) >= (2**63):`, is intended
to handle integers outside the valid `int64` range. However, it contains an off-by-one
error. The valid range for a signed 64-bit integer is `[-2**63, 2**63 - 1]`. When the
input `value` is exactly `-2**63` (the minimum valid value), `abs(value)` becomes
`2**63`, causing the condition to evaluate to `True`. This incorrectly triggers the
conversion of a valid `int64` value to a string, which can lead to data type mismatches
and processing errors in downstream systems that expect an integer.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7204861

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I decided that this doesn't matter.

elif isinstance(value, int):
# int_value is a signed int64, so it has a range of valid values.
# if value doesn't fit into an int64, cast it to string.
if abs(value) >= (2**63):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: Off-by-one error for minimum int64 value

The boundary check abs(value) >= (2**63) incorrectly converts the minimum valid int64 value -2**63 to a string. Since abs(-2**63) equals 2**63, the condition triggers for this valid int64 value. The signed int64 range is [-2**63, 2**63 - 1], so -2**63 is valid. The check could use abs(value) > 2**63 - 1 to handle both boundaries correctly, though this is a minor edge case that doesn't cause errors—it just unnecessarily stringifies one extra value.

Fix in Cursor Fix in Web

@thetruecpaul thetruecpaul enabled auto-merge (squash) December 11, 2025 18:42
@thetruecpaul thetruecpaul merged commit ba0c797 into master Dec 11, 2025
66 checks passed
@thetruecpaul thetruecpaul deleted the cpaul/121125/eapmaxintfix branch December 11, 2025 19:02
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 11, 2025

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/eventstream/item_helpers.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #104787      +/-   ##
===========================================
- Coverage   80.47%    80.47%   -0.01%     
===========================================
  Files        9363      9363              
  Lines      401849    401851       +2     
  Branches    25833     25833              
===========================================
+ Hits       323389    323390       +1     
- Misses      78018     78019       +1     
  Partials      442       442              

@github-actions github-actions bot locked and limited conversation to collaborators Dec 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants