-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #81223: flock() only locks first byte of file
`flock()` should lock the whole file, like on other systems which use mandatory locking. We cannot use `0` like for `flck.l_len`, so we use the largest number, what is valid according to the documentation: <https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-lockfileex#remarks>. Closes GH-7216.
- Loading branch information
Showing
3 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,24 @@ | ||
--TEST-- | ||
Bug #81223 (flock() only locks first byte of file) | ||
--SKIPIF-- | ||
<?php | ||
if (PHP_OS_FAMILY !== "Windows") die("skip for Windows only"); | ||
?> | ||
--FILE-- | ||
<?php | ||
$filename = __FILE__; | ||
$stream1 = fopen($filename, "r"); | ||
var_dump(flock($stream1, LOCK_EX)); | ||
$stream2 = fopen($filename, "r"); | ||
var_dump(fread($stream2, 5)); | ||
fseek($stream2, 1); | ||
var_dump(fread($stream2, 4)); | ||
?> | ||
--EXPECTF-- | ||
bool(true) | ||
|
||
Notice: fread(): read of %d bytes failed with errno=13 Permission denied in %s on line %d | ||
bool(false) | ||
|
||
Notice: fread(): read of %d bytes failed with errno=13 Permission denied in %s on line %d | ||
bool(false) |
520c00a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
(~0)
instead of 0xFF because(~0)
will set every bit, then you don't have to worry about the size of DWORD or how many F's you need ^^