Edit report at https://bugs.php.net/bug.php?id=80933&edit=1
ID: 80933
User updated by: gabrielpl at gmail dot com
Reported by: gabrielpl at gmail dot com
Summary: When flag DROP_NEW_LINE is enabled, line read stops
at null char
Status: Verified
Type: Bug
Package: SPL related
Operating System: Windows
PHP Version: 7.4
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
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?
Previous Comments:
------------------------------------------------------------------------
[2021-04-05 16:35:19] cmb@php.net
The following pull request has been associated:
Patch Name: Fix #80933: SplFileObject::fgets() stops at NUL byte for DROP_NEW_LINE
On GitHub: https://github.com/php/php-src/pull/6836
Patch: https://github.com/php/php-src/pull/6836.patch
------------------------------------------------------------------------
[2021-04-05 15:39:38] cmb@php.net
Good catch, @requinix!
------------------------------------------------------------------------
[2021-04-04 07:04:28] requinix@php.net
Simple naive use of strcspn.
https://github.com/php/php-src/blob/PHP-8.0.3/ext/spl/spl_directory.c#L1891
------------------------------------------------------------------------
[2021-04-04 06:15:52] gabrielpl at gmail dot com
Description:
------------
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:
---------------
<?php
// string with a NULL char
$line = "Lorem ipsum \0 dolor sit amet";
$temp = new SplTempFileObject();
$temp->fwrite($line);
$temp->rewind();
$read = $temp->fgets();
echo 'SplFileObject::DROP_NEW_LINE flag -> disabled' . PHP_EOL;
var_dump(strcmp($line, $read), $read);
$temp->rewind();
$temp->setFlags(SplFileObject::DROP_NEW_LINE);
$read = $temp->fgets();
echo PHP_EOL . 'SplFileObject::DROP_NEW_LINE flag -> enabled' . PHP_EOL;
var_dump(strcmp($line, $read), $read);
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80933&edit=1