Prevent crashing with integeroverflow on optData hashing #15944
Merged
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.
Fixing my own mistake from the past.
When working on nullness PR, there is a situation where a 2nd optimization data resource can exist if compiling with
optimize:+(cc @vzarytovskii )Depending on the contents, adding a hash of the two optimization resources can overflow an int32. Via a regular plus addition, it would just overflow and it would be ok for a hash result - so far so good.
However, the
List.sumByfunction is doing aCheckedaddition and therefore throw at runtime with an integeroverflow. I/We should be definitely more careful about the usage of.sum / .sumByin the compiler codebase.This was really strange to investigate, as only some projects have been failing - depending on the numeric value of their optimization data hashes.