Skip to content

Commit d776413

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #81223: flock() only locks first byte of file
2 parents bcefc31 + 520c00a commit d776413

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ PHP NEWS
3232
. Fixed bug #81208 (Segmentation fault while create newInstance from
3333
attribute). (Nikita)
3434

35+
- Standard:
36+
. Fixed bug #81223 (flock() only locks first byte of file). (cmb)
37+
3538
17 Jun 2021, PHP 8.0.8
3639

3740
- Core:

ext/standard/flock_compat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ PHPAPI int php_flock(int fd, int operation)
103103
*/
104104
{
105105
HANDLE hdl = (HANDLE) _get_osfhandle(fd);
106-
DWORD low = 1, high = 0;
106+
DWORD low = 0xFFFFFFFF, high = 0xFFFFFFFF;
107107
OVERLAPPED offset =
108108
{0, 0, 0, 0, NULL};
109109
DWORD err;

ext/standard/tests/file/bug81223.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #81223 (flock() only locks first byte of file)
3+
--SKIPIF--
4+
<?php
5+
if (PHP_OS_FAMILY !== "Windows") die("skip for Windows only");
6+
?>
7+
--FILE--
8+
<?php
9+
$filename = __FILE__;
10+
$stream1 = fopen($filename, "r");
11+
var_dump(flock($stream1, LOCK_EX));
12+
$stream2 = fopen($filename, "r");
13+
var_dump(fread($stream2, 5));
14+
fseek($stream2, 1);
15+
var_dump(fread($stream2, 4));
16+
?>
17+
--EXPECTF--
18+
bool(true)
19+
20+
Notice: fread(): read of %d bytes failed with errno=13 Permission denied in %s on line %d
21+
bool(false)
22+
23+
Notice: fread(): read of %d bytes failed with errno=13 Permission denied in %s on line %d
24+
bool(false)

0 commit comments

Comments
 (0)