FAQ
Edit report at http://pear.php.net/bugs/bug.php?id=18192&edit=1

ID: 18192
Updated by: tacker@php.net
Reported By: roborg at hotmail dot com
Summary: Improper file opening in _write method
-Status: Open
+Status: Verified
Type: Bug
Package: Cache_Lite
Operating System: All
Package Version: 1.7.8
-PHP Version: 5.2.8
+PHP Version: Irrelevant
-Assigned To:
+Assigned To: tacker
Roadmap Versions:
New Comment:

-Status: Open
+Status: Verified
-PHP Version: 5.2.8
+PHP Version: Irrelevant
-Assigned To:
+Assigned To: tacker



Previous Comments:
------------------------------------------------------------------------

[2011-01-13 12:25:41] roborg

Added #patch bug:18192;patch:patch.txt;revision:1294921541;.

------------------------------------------------------------------------

[2011-01-13 12:16:21] roborg

Description:
------------
The cache file to write to is opened with mode "wb" before it is
locked, so a read can occur between the file being opened
(and truncated) and locked. Running two copies of the test
script simultaneously will show this behaviour.

Suggested fix is to change line 766 onwards from:

$fp = @fopen($this->_file, "wb");
if ($fp) {
if ($this->_fileLocking) @flock($fp, LOCK_EX);

to

$fp = @fopen($this->_file, "cb");
if ($fp) {
if ($this->_fileLocking) @flock($fp, LOCK_EX);
ftruncate($fp, 0);

Test script:
---------------
<?php

require_once 'Cache/Lite.php';

$c = new Cache_Lite(array('cacheDir' => '.'));
$str = 'test';

for ($i = 0; $i < 10000; $i++)
{
if (!$c->save('test', $str))
die('Error saving');

if ($c->get('test') != $str)
die('Wrong data');
}


Expected result:
----------------
No output

Actual result:
--------------
die() is called

------------------------------------------------------------------------

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppear-bugs @
categoriesphp
postedJan 14, '11 at 10:48a
activeJan 14, '11 at 10:48a
posts1
users1
websitepear.php.net

1 user in discussion

Tacker: 1 post

People

Translate

site design / logo © 2022 Grokbase