---
title: "An overflow warning needs a type width and a real value | Proofline"
description: "An overflow or truncation claim is right when a value the code really sees can exceed the width of the type that holds it."
url: https://proofline.sh/learn/ai-review-integer-overflow-comment/
---

[Learning center](/learn/)

# 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.

Code review The Proofline team November 22, 2026 4 min read

## 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](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex)). 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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)). 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](https://go.dev/ref/spec#Integer_overflow)).
-   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](https://doc.rust-lang.org/reference/behavior-not-considered-unsafe.html#integer-overflow)), so a test in a debug build can catch what a release build would wrap.
-   In C and C++, signed overflow is [undefined behavior](https://en.cppreference.com/w/cpp/language/operator_arithmetic#Overflows), 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](/learn/postgres-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](https://github.com/vllm-project/vllm/pull/34279)). 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](https://github.com/vllm-project/vllm/pull/34530))

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](https://github.com/vllm-project/vllm/pull/34530#pullrequestreview-3798833577)) 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](https://github.com/vllm-project/vllm/pull/34507)). 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](https://patch-diff.githubusercontent.com/raw/vllm-project/vllm/pull/34507.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 find | Answer |
| --- | --- |
| Plain Python `int`, or JavaScript `BigInt`, with no fixed-width destination | Dismiss, citing the language semantics |
| A fixed-width type, and the largest real value fits with a wide margin | Dismiss, 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 it | Change 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 vLLM | Widen only the product that can overflow, measure, and defer the rest to an issue with the numbers |
| You cannot bound the input | Treat 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](/learn/review-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](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [How much room is left in a PostgreSQL integer ID](/learn/postgres-integer-id-headroom/)
    
    Capacity overruns The Proofline team November 20, 2026 3 min read
    
-   ### [Do a code reviewer's severity labels mean anything?](/learn/review-severity-calibration/)
    
    Code review The Proofline team November 20, 2026 4 min read
