MDL-57801 core_filestorage: Verify hash of temp file before committing

This addresses an edge scenario on NFS filesystems with no space
remaining, where subsequent uploads fail silently while zero byte files
are saved to the pool (and for some reason the filesize check passes).
This commit is contained in:
Tony Butler
2017-02-16 12:38:58 +00:00
parent 9ec952f237
commit 961323a05f
+3 -3
View File
@@ -424,9 +424,9 @@ class file_system_filedir extends file_system {
ignore_user_abort($prev);
throw new file_exception('storedfilecannotcreatefile');
}
if (filesize($hashfile.'.tmp') !== $filesize) {
// This should not happen.
unlink($hashfile.'.tmp');
if (sha1_file($hashfile.'.tmp') !== $contenthash) {
// Highly unlikely edge case, but this can happen on an NFS volume with no space remaining.
@unlink($hashfile.'.tmp');
ignore_user_abort($prev);
throw new file_exception('storedfilecannotcreatefile');
}