-
Notifications
You must be signed in to change notification settings - Fork 7.9k
fix GH-13203 file_put_contents fail on strings over 4GB on Windows #13205
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
Closed
Closed
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
44e8829
fix GH-13203 file_put_contents fail on strings over 4GB on Windows
divinity76 1158cb1
forgot limits.h
divinity76 f4424ea
Create file_put_contents_5gb.phpt
divinity76 c6b5b3d
fix wmic invocation
divinity76 a2aeff2
PLAIN_WRAP_BUF_SIZE
divinity76 3e63d6a
use int_max...
divinity76 2f9171a
nitpick
divinity76 d549b12
pr nitpick
divinity76 191f1c3
dont use tmpfile (per codereview)
divinity76 7a8d13a
Update file_put_contents_5gb.phpt
divinity76 d45845b
Update plain_wrapper.c
divinity76 04963c5
Update file_put_contents_5gb.phpt
divinity76 59198f3
Update ext/standard/tests/file/file_put_contents_5gb.phpt
divinity76 3a259fb
Update ext/standard/tests/file/file_put_contents_5gb.phpt
divinity76 c8420b1
consistently return bytes
divinity76 d3fc602
skip <40bit systems
divinity76 c689c74
Update ext/standard/tests/file/file_put_contents_5gb.phpt
divinity76 3ff36f6
Update ext/standard/tests/file/file_put_contents_5gb.phpt
divinity76 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--TEST-- | ||
Test file_put_contents() function with 5GB string | ||
--SKIPIF-- | ||
<?php | ||
if (getenv('SKIP_SLOW_TESTS')) { | ||
die('skip slow test'); | ||
} | ||
function get_system_memory(): int|float|false | ||
{ | ||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { | ||
// Windows-based memory check | ||
@exec('wmic OS get FreePhysicalMemory', $output); | ||
if (isset($output[1])) { | ||
return (int)trim($output[1]); | ||
} | ||
} else { | ||
// Unix/Linux-based memory check | ||
$memInfo = @file_get_contents("/proc/meminfo"); | ||
if ($memInfo) { | ||
preg_match('/MemFree:\s+(\d+) kB/', $memInfo, $matches); | ||
return $matches[1] * 1024; // Convert to bytes | ||
divinity76 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
return false; | ||
} | ||
if (get_system_memory() < 10 * 1024 * 1024) { | ||
die('skip Reason: Insufficient RAM (less than 10GB)'); | ||
} | ||
$tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "test_file_put_contents_5gb.bin"; | ||
$tmpfileh = fopen($tmpfile, "wb"); | ||
if ($tmpfileh === false) { | ||
die('skip Reason: Unable to create temporary file'); | ||
} | ||
fclose($tmpfileh); | ||
unlink($tmpfile); | ||
if (disk_free_space(dirname($tmpfile)) < 10 * 1024 * 1024 * 1024) { | ||
die('skip Reason: Insufficient disk space (less than 10GB)'); | ||
} | ||
?> | ||
--INI-- | ||
memory_limit=6G | ||
--FILE-- | ||
<?php | ||
$tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "test_file_put_contents_5gb.bin"; | ||
$large_string = str_repeat('a', 5 * 1024 * 1024 * 1024); | ||
$result = file_put_contents($tmpfile, $large_string); | ||
if ($result !== strlen($large_string)) { | ||
echo "Could only write $result bytes of " . strlen($large_string) . " bytes."; | ||
var_dump(error_get_last()); | ||
} else { | ||
echo "File written successfully."; | ||
} | ||
divinity76 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
clearstatcache(true, $tmpfile); | ||
if(file_exists($tmpfile)) { | ||
divinity76 marked this conversation as resolved.
Show resolved
Hide resolved
divinity76 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
unlink($tmpfile); | ||
} | ||
?> | ||
divinity76 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--CLEAN-- | ||
<?php | ||
@unlink(sys_get_temp_dir() . DIRECTORY_SEPARATOR . "test_file_put_contents_5gb.bin"); | ||
?> | ||
--EXPECT-- | ||
File written successfully. |
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
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.
Uh oh!
There was an error while loading. Please reload this page.