Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file_put_contents fail on strings over 4GB on Windows 10 #13203

Closed
divinity76 opened this issue Jan 20, 2024 · 0 comments
Closed

file_put_contents fail on strings over 4GB on Windows 10 #13203

divinity76 opened this issue Jan 20, 2024 · 0 comments

Comments

@divinity76
Copy link
Contributor

divinity76 commented Jan 20, 2024

Description

The following cmd.exe invocation:

php -r "ini_set('memory_limit', '6G'); $size = 5 * 1024 * 1024 * 1024; $str = str_repeat(\"\x00\", $size); file_put_contents('test.bin', $str);"
dir

Resulted in this output:

C:\reproduce>php -r "ini_set('memory_limit', '6G'); $size = 5 * 1024 * 1024 * 1024; $str = str_repeat(\"\x00\", $size); file_put_contents('test.bin', $str);"
PHP Notice:  file_put_contents(): Write of 4294967295 bytes failed with errno=0 No error in Command line code on line 1

Notice: file_put_contents(): Write of 4294967295 bytes failed with errno=0 No error in Command line code on line 1

C:\reproduce>dir
 Volume in drive C has no label.
 Volume Serial Number is 445C-1EDF

 Directory of C:\reproduce

20/01/2024  18:41    <DIR>          .
20/01/2024  18:41    <DIR>          ..
20/01/2024  18:41     4,294,967,295 test.bin
               1 File(s)  4,294,967,295 bytes
               2 Dir(s)  2,580,218,351,616 bytes free

But I expected this output instead:

C:\reproduce>php -r "ini_set('memory_limit', '6G'); $size = 5 * 1024 * 1024 * 1024; $str = str_repeat(\"\x00\", $size); file_put_contents('test.bin', $str);"

C:\reproduce>dir
 Volume in drive C has no label.
 Volume Serial Number is 445C-1EDF

 Directory of C:\reproduce

20/01/2024  18:41    <DIR>          .
20/01/2024  18:41    <DIR>          ..
20/01/2024  18:41     5,368,709,120 test.bin
               1 File(s)  5,368,709,120 bytes
               2 Dir(s)  2,580,218,351,616 bytes free
  • tested on both 8.3.2 and 8.3.0
  • interestingly, it does /not/ reproduce on Linux.

PHP Version

PHP 8.3.2

Operating System

Windows 10 x64 22H2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants