if #818818: Race Condition when using file_save_data FILE_EXISTS_REPLACE doesn't fix the filesize of zero issue then we need to add in checks to make sure the file we are saving doesn't have a filesize of zero. Problem was discovered in drupal 6.x when writing to a filesystem over a network. Patch will be extracted from the patch in #755586: Fallback for CSS/JS aggregation for non-writable directories.

Comments

mikeytown2’s picture

Status: Active » Needs review
StatusFileSize
new2.32 KB
c960657’s picture

Wouldn't it be better to add proper error handling to file_unmanaged_save_data(), i.e. if it fails to save the file, it should remove the empty file and return FALSE?

mikeytown2’s picture

StatusFileSize
new810 bytes

http://api.drupal.org/api/function/file_unmanaged_save_data/7
Here's a patch for checking filesize in file_unmanaged_save_data.

Status: Needs review » Needs work

The last submitted patch, drupal-828268-D7.patch, failed testing.

mikeytown2’s picture

Status: Needs work » Needs review
StatusFileSize
new836 bytes
mikeytown2’s picture

StatusFileSize
new734 bytes

patch for 6.x

c960657’s picture

-  return file_unmanaged_move($temp_name, $destination, $replace);
+  $path = file_unmanaged_move($temp_name, $destination, $replace);
+
+  // Make sure everything was moved correctly
+  if (strlen($data) > 0 && @filesize($path) == 0) {

If writing the file fails, file_unmanaged_move() is supposed to return FALSE. Shouldn't you just check for that?

mikeytown2’s picture

Status: Needs review » Needs work

good point

mikeytown2’s picture

Status: Needs work » Needs review
StatusFileSize
new787 bytes
new730 bytes
thedavidmeister’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs issue summary update

So, this still seems to be in the same state in 8.x

Patch no longer applies.

The patch in #9 doesn't just affect serving JS/CSS files, it is a blanket modification to file_unmanaged_save_data(). It's unclear from the issue summary and subsequent comments whether the intention is to do this or just handle JS/CSS - if the former, we should be checking the size of $data before doing anything else and bail early if appropriate.

This patch needs tests.

The referenced issue #818818: Race Condition when using file_save_data FILE_EXISTS_REPLACE is closed as a duplicate #1377740: file_unmanaged_move() should issue rename() where possible instead of copy() & unlink(), which doesn't seem to be handling zero size files.

Review bonus #2094585: [policy, no patch] Core review bonus for #1898420: image.module - Convert theme_ functions to Twig.

dawehner’s picture

Component: base system » asset library system
Issue summary: View changes

.

wim leers’s picture

Version: 8.0.x-dev » 7.x-dev
Issue tags: +Needs steps to reproduce

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.