Skip to content

Commit

Permalink
MDL-57801 core_filestorage: Verify hash of temp file before committing
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
tonyjbutler committed Feb 16, 2017
1 parent 9ec952f commit 961323a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/filestorage/file_system_filedir.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ public function add_file_from_path($pathname, $contenthash = null) {
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');
}
Expand Down

0 comments on commit 961323a

Please sign in to comment.