Repository navigation
Fix zend_inference: fix unsound shift_left_overflows range when shift… - #24994
Closed
mkrishna793 wants to merge 2 commits into
Closed
mkrishna793 wants to merge 2 commits into
mkrishna793 wants to merge 2 commits into
Conversation
… wraps shift_left_overflows() previously checked 'safe_shift_left(n, s) > n' for negative numbers, which incorrectly returned false when (n << s) wrapped around to a value <= n (such as ZEND_LONG_MIN or negative wrapped values). Positive shifts also missed overflow when wrapping. Use a round-trip arithmetic shift check ((shifted >> s) != n) to soundly detect overflow across all inputs.
Member
|
Merged in 8df212a. Thank you! |
Contributor
Author
|
thank you so much for merging my commit
|
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.
Summary of Changes
In
Zend/Optimizer/zend_inference.c,shift_left_overflows(n, s)previously checkedsafe_shift_left(n, s) > nfor negative inputs. When(n << s)wrapped around to a value<= n(such asZEND_LONG_MINor negative wrapped values), the check falsely returnedfalse(no overflow). Positive shifts also missed overflow when wrapping around (e.g.7041795614029497201 << 6).This PR replaces the heuristic with a round-trip arithmetic shift check
((shifted >> s) != n)that soundly detects overflow across all 64-bit and 32-bit inputs.Includes the regression test provided by @arnaud-lb in
Zend/tests/shift_left_overflow_range.phpt.