php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76803 ftruncate changes file pointer
Submitted: 2018-08-27 18:33 UTC Modified: 2018-08-28 11:29 UTC
From: david at grudl dot com Assigned: ab (profile)
Status: Closed Package: *Directory/Filesystem functions
PHP Version: 7.3.0beta2 OS: Windows
Private report: No CVE-ID: None
 [2018-08-27 18:33 UTC] david at grudl dot com
Description:
------------
In this code is file pointer changed in PHP 7.3



Test script:
---------------
$f = fopen('test', 'w');
fwrite($f, 'Hello');
ftruncate($f, 2); // in 7.3 changes file pointer to 2
fwrite($f, 'World');
fclose($f);
echo file_get_contents('test');



Expected result:
----------------
Should return "He\x00\x00\x00World"

Actual result:
--------------
'HeWorld'

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-28 00:36 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2018-08-28 00:36 UTC] requinix@php.net
I don't see any change in behavior.

You shouldn't actually see "\x00" in any output. Whether you would see anything at all for those NULs depends.
  echo addslashes(file_get_contents('test'));
 [2018-08-28 09:12 UTC] cmb@php.net
-Status: Feedback +Status: Verified -Operating System: +Operating System: Windows -Assigned To: +Assigned To: ab
 [2018-08-28 09:12 UTC] cmb@php.net
The behavioral change has been introduced with commit 9cd2d77[1],
and affects Windows only.  Before this commit the output with
addslashes has been (and still is on Linux):

  He\0\0\0World

Anatol, would it be possible to restore the former behavior
without loosing the fix for bug #76422?  However, it seems that
memory streams already behave like file streams on Windows now[2].
Maybe we should just document that ftruncate() may affect the
position of the file pointer or not.

[1] <http://git.php.net/?p=php-src.git;a=commit;h=9cd2d77>
[2] <https://3v4l.org/hXXDr>
 [2018-08-28 11:29 UTC] ab@php.net
Thanks for the ping, Christoph. I think, it's a regression and will be working on a fix.

Thanks.
 [2018-08-28 13:44 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7728160784785771d1933f5f0a8c4d7a735470b0
Log: Fixed bug #76803 ftruncate changes file pointer
 [2018-08-28 13:44 UTC] ab@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Thu Dec 13 22:01:26 2018 UTC