PHP readfile() output buffering


#1

Hi everyone,

If output buffering is turned on in php, call to readfile() will trigger php to buffer the whole contents of the file in memory. This will then cause php to display Out of memory error.

The following php files have calls to readfile()
./xibo-cms-1.8.11/lib/Controller/Layout.php:1327: readfile($fileName);
./xibo-cms-1.8.11/lib/Controller/Maintenance.php:446: readfile($zipFile);
./xibo-cms-1.8.11/lib/Helper/BlueImpUploadHandler.php:657: protected function readfile($file_path)
./xibo-cms-1.8.11/lib/Helper/BlueImpUploadHandler.php:659: return readfile($file_path);
./xibo-cms-1.8.11/lib/Helper/BlueImpUploadHandler.php:750: $this->readfile($file_path);
./xibo-cms-1.8.11/lib/Widget/ModuleWidget.php:1115: readfile($libraryPath);

Placing the following code before the call to readfile() will fix the out of memory issue.
if(ob_get_level())
{
ob_end_flush();
}
Code checks to see if output buffering is enabled, then flushes the output buffer and disables output buffering.
PHP is run as an apache module.

Xibo version: 1.8.11
PHP version: 5.6.36
Apache web server: 2.4.34
OS FreeBSD 11.2-RELEASE-p2

Cheers,
Alex.


#2

Thank you for bringing this to our attention, I’ve created an issue in GitHub for it and we will investigate it further from there.


#3

Thank you Peter!

Cheers,
Alex.