View Issue Details

IDProjectCategoryView StatusLast Update
0000234fileGeneralpublic2021-02-05 21:34
Reporterhalaei Assigned Tochristos  
PrioritynormalSeveritymajorReproducibilityhave not tried
Status resolvedResolutionfixed 
Product Version5.38 
Fixed in Version5.40 
Summary0000234: Memory problems running finfo::buffer with PHP_CLI
DescriptionPHP internally uses libmagic for getting information about files. This sample php code consumes 483 MB of RAM for detecting mimetype of a 48 MB MP3 file using php7.4 but it uses only 56 MB with php7.2.

    $finfo = new finfo(FILEINFO_MIME_TYPE, '');
    $contents = file_get_contents('file.mp3');
    echo($finfo->buffer($contents));

The bug is reported to php as well. They say it should be reported to libmagic. See https://bugs.php.net/bug.php?id=79263

The PHP bug is over 1 year old.
I reported the bug here as well: https://bugs.launchpad.net/ubuntu/+bug/1914401 .Maybe it wasn't the right place
Steps To ReproduceHaving a large file.mp3 file. Run the following using php 7.4:

<?php
    $finfo = new finfo(FILEINFO_MIME_TYPE, '');
    $contents = file_get_contents('file.mp3');
    echo($finfo->buffer($contents));
    echo(memory_get_peak_usage(true)/1024/1024);
TagsNo tags attached.

Activities

christos

2021-02-05 21:34

manager   ~0003533

file_buffer(3) passed the full size of the buffer to the encoding
determination function. If the file was too large, we ended up
allocating (2 * size + 4 * size) buffers to scan for encoding. Now
we limit size to 64K.

Issue History

Date Modified Username Field Change
2021-02-03 12:13 halaei New Issue
2021-02-05 21:34 christos Assigned To => christos
2021-02-05 21:34 christos Status new => assigned
2021-02-05 21:34 christos Status assigned => resolved
2021-02-05 21:34 christos Resolution open => fixed
2021-02-05 21:34 christos Fixed in Version => 5.40
2021-02-05 21:34 christos Note Added: 0003533