Skip to content

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

Closed

Description

@divinity76

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

Activity

  1. added a commit that references this issue on Jan 20, 2024
    44e8829
  2. added a commit that references this issue on Mar 9, 2024
    2343791
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions