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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cmb@php.net
New email:
PHP Version: OS:

 

 [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

Pull Requests

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 Oct 11 14:01:27 2024 UTC