php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81223 flock() only locks first byte of file
Submitted: 2021-07-05 14:14 UTC Modified: 2021-07-05 14:14 UTC
From: cmb@php.net Assigned: cmb (profile)
Status: Closed Package: Filesystem function related
PHP Version: 7.4Git-2021-07-05 (Git) OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
26 + 30 = ?
Subscribe to this entry?

 
 [2021-07-05 14:14 UTC] cmb@php.net
Description:
------------
On Windows, flock() only locks the first byte of the file, so that
fseeking beyond that first byte allows accessing the file
contents.

Test script:
---------------
<?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));
?>


Expected result:
----------------
bool(true)
bool(false)
bool(false)


Actual result:
--------------
bool(true)
bool(false)
string(4) "?php"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-05 14:14 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2021-07-06 10:04 UTC] git@php.net
Automatic comment on behalf of cmb69
Revision: https://github.com/php/php-src/commit/520c00a5bffd87a5318c487bf1b778a53e8298d4
Log: Fix #81223: flock() only locks first byte of file
 [2021-07-06 10:04 UTC] git@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 13:01:29 2024 UTC