|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80933 SplFileObject::DROP_NEW_LINE is broken for NUL and CR
Submitted: 2021-04-04 06:15 UTC Modified: 2021-04-07 10:08 UTC
From: gabrielpl at gmail dot com Assigned: cmb (profile)
Status: Closed Package: SPL related
PHP Version: 7.4 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
31 - 5 = ?
Subscribe to this entry?

 [2021-04-04 06:15 UTC] gabrielpl at gmail dot com
When the flag DROP_NEW_LINE is enabled in SplFileObject classes, reading a line (e.g. fgets()) stops at null char.

When the flag is disabled, the read operation works as intended.

Test script:

// string with a NULL char
$line = "Lorem ipsum \0 dolor sit amet";

$temp = new SplTempFileObject();

$read = $temp->fgets();
echo 'SplFileObject::DROP_NEW_LINE flag -> disabled' . PHP_EOL;
var_dump(strcmp($line, $read), $read);

$read = $temp->fgets();
echo PHP_EOL . 'SplFileObject::DROP_NEW_LINE flag -> enabled' . PHP_EOL;
var_dump(strcmp($line, $read), $read);


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-04 07:04 UTC]
-Status: Open +Status: Verified
 [2021-04-05 15:39 UTC]
-PHP Version: 8.0.3 +PHP Version: 7.4 -Assigned To: +Assigned To: cmb
 [2021-04-05 15:39 UTC]
Good catch, @requinix!
 [2021-04-05 16:35 UTC]
The following pull request has been associated:

Patch Name: Fix #80933: SplFileObject::fgets() stops at NUL byte for DROP_NEW_LINE
On GitHub:
 [2021-04-07 00:34 UTC] gabrielpl at gmail dot com
Looking the original source and the patch #80933...
I think the following string will not pass the test:

// string with a carriage return char
$line = "Lorem ipsum \r dolor sit amet";

Could someone confirm?
 [2021-04-07 10:08 UTC]
-Summary: When flag DROP_NEW_LINE is enabled, line read stops at null char +Summary: SplFileObject::DROP_NEW_LINE is broken for NUL and CR
 [2021-04-07 10:08 UTC]
Indeed, you're right!  We need to use php_stream_locate_eol()
instead of (php_)strcspn() to properly detect the line endings.
 [2021-04-13 14:50 UTC]
Automatic comment on behalf of cmb69
Log: Fix #80933: SplFileObject::DROP_NEW_LINE is broken for NUL and CR
 [2021-04-13 14:50 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Jun 14 19:01:23 2021 UTC