Skip to content

umask(): 2^32 narrows to zero and disables permission masking #25967

Backlog

Description

@kid-lxy

Description

The following code:

<?php
umask(077);
umask(4294967296);
var_dump(umask());
$p = tempnam(sys_get_temp_dir(), 'php-umask-');
unlink($p);
file_put_contents($p, 'x');
clearstatcache();
printf("created mode: %04o\n", fileperms($p) & 0777);
unlink($p);

Resulted in this output:

int(0)
created mode: 0666

But I expected this output instead:

int(63)
created mode: 0600

ext/standard/file.c:1244 calls umask((int) mask) without checking whether the 64-bit zend_long is representable as an int; on this platform, 4294967296 narrows to zero and clears the process mask. The out-of-range request must be rejected without replacing the existing 077 mask, so ordinary 0666 file creation remains restricted to 0600.

PHP Version

PHP 8.7.0-dev (cli) (built: Nov 29 2026 03:42:09) (NTS)
Copyright © The PHP Group and Contributors
Zend Engine v4.7.0-dev, Copyright © Zend by Perforce
    with Zend OPcache v8.7.0-dev, Copyright ©, by Zend by Perforce

Operating System

Ubuntu 24.04.5 LTS

Activity

  1. added 2 commits that reference this issue on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions