[php-src] Issue #10198: fgets() sometimes does not read a full line

From: Date: Sat, 31 Dec 2022 14:45:52 +0000
Subject: [php-src] Issue #10198: fgets() sometimes does not read a full line
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-243304@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/10198 Author: sboden ### Description fgets() sometimes does not read a full line. I'm reading old style fixed format ASCII files using PHP 8.0.26 (from the official docker image). The file only contains [a-zA-Z0-9], spaces and newlines. Every line in the file is exactly 559 characters long. The file gets downloaded to a local file system before the file is opened. ```php <?php ... if ($file = fopen($real_directory . '/' . $content, "r")) { $line_nr = 0; while (!feof($file)) { $line_nr++; $line = rtrim(fgets($file)); // Get some fields from $line using substr(). } fclose($file); } ``` Once every about 300K lines a line is not completely read into $line, and the substr() fails to get the data I expect: at a specific location in each line there's either the keyword 'IMPORTED' or 'REJECTED'. If that happens the code stops (by intention) as something would be wrong with the input file. Afterwards when I look at the "corrupted" file, the file is completely normal: no escape characters, nothing out of the ordinary. When I reprocess the file unchanged, it goes through without complaining (finding for the line with the latter problem the proper keyword). I see it happening (although seldom), and I can't replicate it consistently. ### PHP Version PHP 8.0.26 ### Operating System Debian GNU/Linux 11 (bullseye)

« previous php.bugs (#243304) next »