-
Bug
-
Resolution: Fixed
-
Major
-
3.5.3
-
MOODLE_35_STABLE
-
MOODLE_35_STABLE, MOODLE_36_STABLE
-
MDL-64497-master -
Here is some code from moodle_content_writer::get_file_content:
$filepointer = fopen($filepath, 'r');
|
while (!feof($filepointer)) {
|
// ...
|
}
|
The 'fopen' returns FALSE on error. Meanwhile, feof returns FALSE if its file pointer is not valid, such as when you pass in FALSE. (See second big red 'WARNING' box on the PHP manual page.)
This error condition could occur for a variety of reasons (e.g. temporary file system failure) or possibly if there is a bug in a plugin's provider implementation. If it does occur, the consequences are likely to be terminal for the server unless an operator takes prompt action. In our case on a test server this endless loop, with PHP warnings occuring each time, caused the PHP error log to reach 56 GB and run out of space in the partition within an hour or so, so that the test server was not able to respond to requests.
We would rather this doesn't happen on the production server.
In addition I noticed another error, which is that this function never calls fclose($filepointer). It's possible that this may have been what caused it to fail in the first place (if it opened many thousands of files using this function in the same request).
Finally, er, I can't see any reason this function is different from file_get_contents, other than having two critical bugs in it.
I am submitting a fix as follows:
1. Replace the entire contents of the buggy function with a call to file_get_contents.
2. Check the return value and throw an exception if it failed.
3. Also throw an exception if it fails writing the file, so that we detect the error closer to the point it occurs.
- is a regression caused by
-
MDL-62491 Privacy Data Request Export Format
- Closed