php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64060 Test lstat_stat_variation7 incorrectly fails on certain file systems
Submitted: 2013-01-23 23:13 UTC Modified: 2020-10-02 16:54 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: m dot voelker at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Testing related
PHP Version: 5.4.11 OS: Linux
Private report: No CVE-ID: None
 [2013-01-23 23:13 UTC] m dot voelker at gmail dot com
Description:
------------
This applies to PHP 5.4.11 as well as 5.3.21.

Test ext/standard/tests/file/lstat_stat_variation7.phpt may incorrectly fail on delayed allocation file systems (in this case XFS on Linux).

Problem:
http://php.net/manual/en/function.stat.php
field 12 is "number of 512-byte blocks allocated"

The test does not fclose() the test file after writing to it, therefore zero 512-byte blocks are allocated even though the file size is 45056 bytes.

Fix:
Change lstat_stat_variation7.phpt from

// writing to an empty file
echo "*** Testing stat() on file after data is written in it ***\n";
$fh = fopen($file_name,"w");
$old_stat = stat($file_name);
clearstatcache();
fwrite($fh, str_repeat((binary)"Hello World", $old_stat['blksize']));
$new_stat = stat($file_name);

to

// writing to an empty file
echo "*** Testing stat() on file after data is written in it ***\n";
$fh = fopen($file_name,"w");
$old_stat = stat($file_name);
clearstatcache();
fwrite($fh, str_repeat((binary)"Hello World", $old_stat['blksize']));
fclose($fh);
$new_stat = stat($file_name);

and the test succeeds.


Test script:
---------------
File: ext/standard/tests/file/lstat_stat_variation7.php

To confirm, modify $file_name = "$file_path/lstat_stat_variation7.tmp"; to use a different file system and run ext/standard/tests/file/lstat_stat_variation7.sh.


Expected result:
----------------
Build of PHP 5.4.11

Test executed on ext2:

*** Testing stat() on file after data is written in it ***
bool(true)
bool(true)
bool(true)

--- Done ---


Actual result:
--------------
Same test executed on XFS:

*** Testing stat() on file after data is written in it ***
bool(true)
bool(true)
Error: stat1 is not lesser than stat2 at key value: 12
Error: stat1 is not lesser than stat2 at key value: blocks

 Dumping stat array 1...
...

  ["size"]=>
  int(0)
...
  ["blocks"]=>
  int(0)

 Dumping stat array 2...
...
  ["size"]=>
  int(45056)
...
  ["blocks"]=>
  int(0)


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-23 13:36 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #64060: Test lstat_stat_variation7 incorrectly fails on certain f…
On GitHub:  https://github.com/php/php-src/pull/6194
Patch:      https://github.com/php/php-src/pull/6194.patch
 [2020-10-02 16:54 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=54435c9b43fb568590b223a24dcf582f1292a5d8
Log: Fix #64060: lstat_stat_variation7.phpt fails on certain file systems
 [2020-10-02 16:54 UTC] cmb@php.net
-Status: Open +Status: Closed
 [2020-10-02 16:54 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC