php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75649 fgets second parameter causes memory leak
Submitted: 2017-12-07 17:46 UTC Modified: 2021-03-28 04:22 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: zoolyka at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: Filesystem function related
PHP Version: 5.6.32 OS: ubuntu
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-12-07 17:46 UTC] zoolyka at gmail dot com
Description:
------------
If I specify a larger number then 8192 for fgets's length then PHP process starts to eat memory.

Test script:
---------------
<?php

$handle = fopen('multi_gb_file', 'r');
while (
  ! feof($handle)
) {
  $buffer = fgets($handle, 10485760);
}
fclose($handle);

?>

Expected result:
----------------
If length is much more then 8192 and the opened file is really huge then memory usage will rise up to the size of the readed file's size.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-16 12:03 UTC] cmb@php.net
-Status: Open +Status: Feedback -Package: *General Issues +Package: Filesystem function related -Assigned To: +Assigned To: cmb
 [2021-03-16 12:03 UTC] cmb@php.net
I cannot reproduce this with PHP-7.4.  Is this still an issue for
you with any of the actively supported PHP versions[1]?

[1] <https://www.php.net/supported-versions.php>
 [2021-03-28 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 06:01:29 2024 UTC