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: -
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: m dot voelker at gmail dot com Assigned:
Status: Open Package: Testing related
PHP Version: 5.4.11 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-04-21 19:25 UTC] salathe@php.net
Automatic comment from SVN on behalf of salathe
Revision: http://svn.php.net/viewvc/?view=revision&revision=333387
Log: Better bitmask for "all errors except E_NOTICE"

Cf user note http://www.php.net/manual/en/function.error-
reporting.php#64060

^ is the xor (bit flipping) operator and would actually turn notices
*on* if they were previously off (in the error level on its left).

Patch by anonymous 43247
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Sep 21 15:01:27 2019 UTC