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:46:46 +00:00
parent 1a754e8446
commit dcd27d9cee
+3 -3
View File
@@ -2004,9 +2004,9 @@ class file_storage {
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');
}