Skip to content

fix: reject out-of-range int32 object conversions - #26

Merged
ruoka merged 1 commit into
masterfrom
cursor/critical-bug-management-e1b1
Jul 27, 2026
Merged

fix: reject out-of-range int32 object conversions#26
ruoka merged 1 commit into
masterfrom
cursor/critical-bug-management-e1b1

Conversation

@cursor

@cursor cursor Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

fix: reject out-of-range int32 object conversions

Bug and impact

object::operator int32_type() narrowed int64 values with no range check. Assignments like int x = doc["id"] / int32_type x = … preferred this conversion over integer_type(), so values outside [INT32_MIN, INT32_MAX] (e.g. 3000000000) silently wrapped to a wrong int — data corruption for JSON/FSON integer fields larger than 32 bits.

Root cause

The conversion did return std::get<integer_type>(…); into int32_type, which is a narrowing conversion with no bounds check.

Fix

Reject out-of-range integers with runtime_error before narrowing; in-range int32 and explicit integer_type extraction unchanged.

Validation

  • Added Int32ConversionRejectsOutOfRange covering oversize/undersize throws, in-range min/max, and integer_type extraction.
  • ./tools/CB.sh debug test --tags='\[xson\]' — 424/424 passed.
Open in Web View Automation 

operator int32_type() narrowed int64 values without a range check, so
`int x = doc["id"]` silently wrapped values outside INT32 bounds.

Co-authored-by: Kaius  Ruokonen <ruoka@users.noreply.github.com>
@ruoka
ruoka marked this pull request as ready for review July 27, 2026 15:11
@ruoka
ruoka merged commit 1171ca6 into master Jul 27, 2026
4 checks passed
@ruoka
ruoka deleted the cursor/critical-bug-management-e1b1 branch July 27, 2026 15:11
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