Skip to content

fix(validators): state the exact 64-bit bounds in the Integer description - #14584

Merged
abnegate merged 5 commits into
mainfrom
qfix-validators-int64
Oct 16, 2026
Merged

abnegate merged 5 commits into
mainfrom
qfix-validators-int64

Conversation

@abnegate

Copy link
Copy Markdown
Member

What

Staging QA: a bigint column bound out of range answered "…between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,808". The real int64 maximum is …807.

Why

packages/validators/src/Integer.php (utopia-php/validators, absorbed into this monorepo) computed its bounds as (2 ** ($bits - 1)) - 1. ** returns a float once the result passes PHP_INT_MAX, so the 64-bit maximum became 9.2233720368547758E18, and number_format() rounded it to …808.

Fix

getMin()/getMax() compute integer bounds: PHP_INT_MAX >> (64 - $bits) for signed and (1 << $bits) - 1 for unsigned (64-bit unsigned is already refused). getDescription() and isValid() both use them, so validation now compares ints with ints. Added a CHANGELOG entry under Unreleased.

Tests

Test origin/main this PR
packages/validators/tests/IntegerTest::testDescriptionStatesTheExactBounds (int64, int32, uint32, int8) ❌ …854,775,808 ✅ …854,775,807
IntegerTest::testSixtyFourBitBoundsAreInclusive (PHP_INT_MAX/MIN, loose strings one past each bound) ✅ ✅
E2E TablesDBColumnsTest::testBigIntColumnBoundOutOfRangeStatesTheInt64Range (POST …/columns/bigint with max: 1e19) ❌ message ends …775,808 or null ✅ …775,807 or null

bin/monorepo check validators passes, and the full TablesDBColumnsTest passes locally.

🤖 Generated with Claude Code

…tion

Integer computed its bounds with **, which returns a float once the result
passes PHP_INT_MAX, so (2 ** 63) - 1 became 9.2233720368547758E18 and the
description printed the signed 64-bit maximum as 9,223,372,036,854,775,808.
The bounds are now integers shifted from PHP_INT_MAX, so the description
reads 9,223,372,036,854,775,807 and validation compares ints with ints.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@luxor-code-review

luxor-code-review Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR fixes a precision bug in packages/validators/src/Integer.php where bounds computed with ** overflowed to float past PHP_INT_MAX, so the validator described the signed 64-bit maximum as 9,223,372,036,854,775,808. The bounds logic is refactored into private getMin()/getMax() helpers using shift-based arithmetic that stays exact within integer precision, and isValid() and getDescription() now share those helpers. Regression coverage is added at both the unit and API layers.

Files Change
packages/validators/src/Integer.php, packages/validators/CHANGELOG.md Replace float-prone ** bound computation with exact shift-based getMin()/getMax() helpers used by both validation and description; changelog entry for the fix
packages/validators/tests/IntegerTest.php Unit tests asserting exact 8/32/64-bit bound strings and inclusive int64 edge values in strict and loose modes
tests/e2e/Services/Databases/TablesDB/TablesDBColumnsTest.php E2E test asserting a bigint column with an out-of-range max (1e19) returns 400 with the corrected int64 range message

Reviewed commit: 44c2e86

@ghost

ghost commented Oct 16, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental changes preserve the intended native-width bounds, and no actionable defect remains in the reviewed changes.

The Integer validator now derives validation bounds and descriptions from the same integer limits, correcting the signed 64-bit maximum. The PR adds unit and end-to-end regressions for exact range messages and inclusive 64-bit boundaries, and records the fix in the validators changelog.

Latest changes: The newest commit rejects integer widths that cannot fit the current PHP build and simplifies the maximum calculation based on that constraint.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
packages/validators/CHANGELOG.md Documents the corrected signed 64-bit maximum under Unreleased.
packages/validators/src/Integer.php Shares integer bounds between descriptions and validation, with native-width checks and calculations.
packages/validators/tests/IntegerTest.php Tests exact bounds in descriptions and inclusive signed 64-bit limits.
tests/e2e/Services/Databases/TablesDB/TablesDBColumnsTest.php Adds an API regression asserting the exact int64 range in a bigint column validation error.

Merged main (9066a1a); no changes to this PR's code since e444b2c · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · See the inline comments. Summary

Comment thread packages/validators/src/Integer.php Resolved
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → qfix-validators-int64 (after).

Metric Before After Change
🚀 Requests/sec 213.7 219.71 ⚪ +2.8%
⏱️ Latency P50 80.63 ms 80.1 ms ⚪ -0.7%
⏱️ Latency P95 184.52 ms 178.43 ms ⚪ -3.3%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 80.1 178.43 13,680 219.71 -6.09
Account 145.54 267.45 720 12.28 +12.95
TablesDB 79.15 143.21 7,440 121.69 -2.63
Storage 71.72 162.53 3,600 60.83 -21.31
Functions 108.86 210.33 1,920 33.09 -4.54

Top API waits (after)

API request Max wait (ms)
account.name.update 393.35
tablesdb.rows.create 380.52
functions.create 378.02
account.prefs.update 371.87
functions.delete 323.03

abnegate and others added 2 commits October 16, 2026 21:38
The shifts assumed 64-bit PHP integers. On 32-bit PHP a signed 8-bit
validator would compute a maximum of 0; the bounds now shift from the native
width and clamp a width PHP cannot represent to PHP_INT_MAX.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · See the inline comments. Summary

Comment thread packages/validators/src/Integer.php Resolved
Clamping a width wider than the native integers to PHP_INT_MAX made a uint32
validator on 32-bit PHP describe its maximum as 2,147,483,647. A width that
does not fit is now refused at construction, as 64-bit unsigned already was,
so every validator that exists states its exact bounds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@abnegate
abnegate merged commit be31cb7 into main Oct 16, 2026
81 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Oct 21, 2026
6 tasks
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.

1 participant