Prevent silent integer overflows in arithmetic operators - #6481
Open
rostan-t wants to merge 2 commits into
Open
Conversation
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
Contributor
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 for
OpSpec::AddArgis already registered asint64_t:DALI/dali/python/backend_impl.cc
Line 3414 in 3e40f6d
And the argument storage uses
int64_tfor all integral types anyway:DALI/dali/pipeline/operator/argument.h
Lines 32 to 37 in 3e40f6d
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:
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: N/A