Learning center

An overflow warning needs a type width and a real value

An overflow or truncation claim is right when a value the code really sees can exceed the width of the type that holds it. Find the type the arithmetic actually runs in, then the largest value that reaches it. If that value fits with margin, dismiss the comment and name both numbers. If it does not, or you cannot bound it, widen the type and add a test at a size that crosses the limit.

Find the type the arithmetic runs in#

The same line of arithmetic overflows in one language and not in another, so start with the semantics, not the expression:

  • Python's int cannot overflow, because Python integers have arbitrary precision (numeric types). A bot comment about overflow in plain Python arithmetic is wrong on that ground alone.
  • NumPy, PyTorch and GPU kernel languages such as Triton use fixed-width types. The same Python-looking expression wraps when its operands are int32 arrays or tensors.
  • JavaScript's Number represents integers exactly only up to Number.MAX_SAFE_INTEGER, which is 2**53 - 1 (MDN). Beyond it, values lose precision rather than wrap: 2**53 + 1 prints 9007199254740992. A 64-bit ID parsed from JSON is a common case.
  • Go's signed integers "may legally overflow", and "Overflow does not cause a run-time panic" (Go specification).
  • Rust panics on overflow when debug assertions are on. "Other kinds of builds may result in panics or silently wrapped values on overflow" (Rust reference), so a test in a debug build can catch what a release build would wrap.
  • In C and C++, signed overflow is undefined behavior, and the compiler may assume it never happens.

Then check where the result goes. A Python int written to an integer database column or packed into a 32-bit field overflows at that boundary, not in the arithmetic. The guide on PostgreSQL integer ID headroom covers the database case.

Follow an overflow that a revert brought back#

In February 2026, a vLLM pull request fixed a crash in the fused mixture-of-experts Triton kernels by annotating every stride parameter as tl.int64. Its description said an offset "exceeds int32 max (~2.1 billion)" for large batches when chunking is disabled (pull request). Users then reported large slowdowns on smaller GPUs, and two days after the merge a maintainer opened a revert: "Reverts #34279 due to large performance degradations reported." (revert)

gemini-code-assist reviewed the revert: "While this action knowingly reintroduces a bug concerning potential integer overflows with very large tensors, it is a pragmatic trade-off to restore performance." (review) The claim was right, and no one disputed it. The revert merged the same day, and a separate pull request opened that day narrowed the fix.

That pull request named the exact product: "stride_cm * offs_token (where stride_cm = N = w1.size(1) and offs_token up to M*topk) can exceed int32 max", with the example "(product = 4096 * 600000 = 2.46B > int32 max)" (pull request). Instead of widening every stride, it widened only the token offset after loading it:

-    offs_token = tl.load(sorted_token_ids_ptr + offs_token_id)
+    # Cast to int64 to prevent overflow in stride*offset products
+    offs_token = tl.load(sorted_token_ids_ptr + offs_token_id).to(tl.int64)

Diff

The arithmetic checks out. 4096 × 600,000 is 2,457,600,000, above the int32 maximum of 2,147,483,647, and NumPy with int32 operands gives -1837367296 for the same product, which as a memory offset points outside the tensor. The pull request merged on 17 February 2026. One reviewer reported that on an AMD GPU the cast still did not recover the original performance, and that was unresolved at merge.

Make the test prove it crosses the limit#

The regression test in that pull request, test_fused_moe_int64_overflow, runs with m, n, k, e, topk = 100000, 2048, 1024, 8, 6 and chunking disabled. Before running the kernel, it asserts that its own sizes reach the overflow:

N = w1.size(1)
assert N * m * topk > 2**31 - 1, "Test params don't trigger int32 overflow"

With N at 2 × 2048, the product is 4096 × 100,000 × 6, the same 2,457,600,000. The author reported that the test fails on the main branch and passes with the fix. The assertion matters as much as the kernel run. A test at sizes below the limit passes with or without the fix, and someone shrinking the test to save GPU memory would otherwise turn it into one that proves nothing.

Decide from the width and the range#

What you findAnswer
Plain Python int, or JavaScript BigInt, with no fixed-width destinationDismiss, citing the language semantics
A fixed-width type, and the largest real value fits with a wide marginDismiss, naming the type's limit and the largest value with its source, such as a schema limit or a configuration maximum
A fixed-width type, and real inputs can exceed itChange the type at the narrowest point that fixes it, and add a test whose sizes are asserted to cross the limit
The fix costs performance or memory, as in vLLMWiden only the product that can overflow, measure, and defer the rest to an issue with the numbers
You cannot bound the inputTreat it as the third row, or add a range check that fails loudly

The second row needs a source for the largest value. "IDs will never get that big" is a guess, not a bound. A column type, a validated request limit or a configured maximum is something the next reviewer can check, and a severity calibration for overflow comments should give more weight to those whose values come from users than to those bounded by configuration.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading