Repository navigation
Fix GH-25967: umask() narrows out-of-range values to int - #25970
Open
sanketpatel32 wants to merge 4 commits into
Open
sanketpatel32 wants to merge 4 commits into
sanketpatel32 wants to merge 4 commits into
Conversation
LamentXU123
requested changes
Nov 30, 2026
LamentXU123
left a comment
Member
There was a problem hiding this comment.
I don't think the current fix is correct. We have an example in the man page that use umask(0)
https://www.php.net/manual/en/function.umask.php#refsect1-function.umask-examples
If I am remembering correct, macOS preserve bit masks smaller than 07777. If PHP's process inherits from 01022, ,umask(0) might get 01022. And umask(01022) will get a ValueError. I suggest we just
- if (!mask_is_null && (mask < 0 || mask > 0777)) {
- zend_argument_value_error(1, "must be between 0 and 0777");
+ if (!mask_is_null && !ZEND_IN_RANGE_OF(mask, int)) {
+ zend_argument_value_error(1, "must be between %d and %d", INT_MIN, INT_MAX);
RETURN_THROWS();
}Please wait for other's review since this is not my field so I am not sure.
Author
|
@LamentXU123 Thanks for the review — updated in 71dc625 to reject only values outside the |
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
Fixes #25967.
umask()now rejects explicitly provided masks that are not representable as anintbefore probing or changing the process umask. This prevents largezend_longvalues from narrowing through(int)and inadvertently clearing or altering the process mask, while preserving round-trips for platform-supported masks above0777such as01022. The prior mask andBG(umask)bookkeeping remain untouched on the error path.This targets
masterbecause rejecting invalid input with a newValueErroris a behavior change. It can be backported to the lowest supported bugfix branch if the maintainers prefer.Adds
ext/standard/tests/file/gh25967.phptcovering positive and negative out-of-int-range values, acceptance of01022, and preservation of the prior mask on errors.Tests
./buildconf && ./configure --disable-all --enable-debug && make -j$(nproc)make test TESTS=ext/standard/tests/file/— 915 tests: 624 passed, 291 skipped, 0 failed