Bug #80933 [Ver]: When flag DROP_NEW_LINE is enabled, line read stops at null char

From: Date: Mon, 05 Apr 2021 15:39:38 +0000
Subject: Bug #80933 [Ver]: When flag DROP_NEW_LINE is enabled, line read stops at null char
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233167@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80933&edit=1

 ID:                 80933
 Updated by:         cmb@php.net
 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:        8.0.3
+PHP Version:        7.4
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Good catch, @requinix!


Previous Comments:
------------------------------------------------------------------------
[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


Thread (7 messages)

« previous php.bugs (#233167) next »