Martin/Dan,
I didn't think the issue was necessarily a 'bug' , more of a failing of Ubuntu 14.04's version of PHP to handle the output buffer cleanly, so I thought it best to post it on here instead.
I suppose it could be seen as a feature request or enhancement?
Also, after applying this patch I noticed files over 10Mb are still affected and checked filelib.php again and found the culprit:
if ($filesize > 10000000) {
// for large files try to flush and close all buffers to conserve memory
while(@ob_get_level()) {
if (!@ob_end_flush()) {
break;
}
}
}
It seems that after flushing the buffer, it causes the corruption issue to arise again. Therefore, I simply decided to comment it out and all files including much larger files (under 2 Gb) downloaded and opened successfully. I'm not sure how critical it is to flush the buffer since it's probably being re-used with each new request and the default buffer size isn't particularly large so I'm sure most servers are not sending files simultaneously in split-seconds and can handle it?
I suppose it might still be worth making a bug report and see if it is given any consideration to be factored into the file handling subroutines when releasing new builds of Moodle.
Out of interest, can you output the results of 'php -v' from the command line and share your version of PHP and we can see if our versions match?
Cheers,
Richard