Skip to content

Prevent silent integer overflows in arithmetic operators - #6481

Open
rostan-t wants to merge 2 commits into
NVIDIA:mainfrom
rostan-t:fix-arithmetic-int-overflows
Open

Prevent silent integer overflows in arithmetic operators#6481
rostan-t wants to merge 2 commits into
NVIDIA:mainfrom
rostan-t:fix-arithmetic-int-overflows

Conversation

@rostan-t

Copy link
Copy Markdown
Collaborator

Category:

Breaking change (fix or feature that would cause existing functionality to not work as expected)

Description:

Currently, arithmetic operators pull constant integers and 32 bits signed ints. As a result, silent overflows can happen, producing wrong results without any warning nor error.

The Python binding forOpSpec::AddArg is already registered as int64_t:

DALI_OPSPEC_ADDARG(int64_t)

And the argument storage uses int64_t for all integral types anyway:

template <typename T>
struct argument_storage {
using type = std::conditional_t<
std::is_integral<T>::value || std::is_enum<T>::value,
int64_t, T>;
};

So we can pull the integer constants as 64 bit integers and error out if any doesn't fit an int32_t.

Additional information:

This is technically a breaking change for uint32 because it used to work accidentally. For instance types.Constant(2**32-1, dtype=types.UINT32) would previously be truncated and the unsigned cast would turn it back to the right value. This raises an exception with this PR.

Affected modules and functionalities:

Integral constants in arithmetic operators.

Key points relevant for the review:

Tests:

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: N/A

Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
@greptile-apps

greptile-apps Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge, with the intentional signed 32-bit compatibility break clearly enforced and tested.

Summary

  • Adds signed 32-bit range validation for arithmetic integer constants.
  • Preserves overflow exception typing and contextual error messages.
  • Adds Python coverage for values immediately above and below the accepted range.

Reviews (1) · Last reviewed commit: "Validate int constant bounds in expressi..."

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