|  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: david at grudl dot com
New email:
PHP Version: OS:


 [2018-08-27 18:33 UTC] david at grudl dot com
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');
echo file_get_contents('test');

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

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-28 00:36 UTC]
-Status: Open +Status: Feedback
 [2018-08-28 00:36 UTC]
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]
-Status: Feedback +Status: Verified -Operating System: +Operating System: Windows -Assigned To: +Assigned To: ab
 [2018-08-28 09:12 UTC]
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):


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] <;a=commit;h=9cd2d77>
[2] <>
 [2018-08-28 11:29 UTC]
Thanks for the ping, Christoph. I think, it's a regression and will be working on a fix.

 [2018-08-28 13:44 UTC]
Automatic comment on behalf of ab
Log: Fixed bug #76803 ftruncate changes file pointer
 [2018-08-28 13:44 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Sep 30 00:01:24 2023 UTC