When you deliver the created archive/zip file via private file system, the downloaded file will be corrupted because a wrong filesize got saved into the file_managed table.

I added clearstatcache(); to clear the cache of the filesize() function.

CommentFileSizeAuthor
#2 clear_filesize_cache-2743999-2.patch590 byteshaggins

Comments

haggins created an issue. See original summary.

haggins’s picture

Status: Active » Needs review
StatusFileSize
new590 bytes
haggins’s picture

Issue summary: View changes
hobbsgoblin’s picture

The patch worked for me.

haggins’s picture

Status: Needs review » Reviewed & tested by the community

Setting to RTBC thanks to #4

joelpittet’s picture

How is the wrong size getting into the stat cache in the first place?

Can you add the steps needed to reproduce this?

haggins’s picture

I'm no longer employed at the company which worked on that particular project. So I can just try to recall what happened:

From the documentation of clearstatcache (https://secure.php.net/manual/en/function.clearstatcache.php):

Affected functions include stat(), lstat(), file_exists(), is_writable(), is_readable(), is_executable(), is_file(), is_dir(), is_link(), filectime(), fileatime(), filemtime(), fileinode(), filegroup(), fileowner(), filesize(), filetype(), and fileperms().

I guess this happens if you archive enough files at once so that more than one batch iteration is necessary. Then we may get the too small size cached by the following lines:

if (file_exists($destination)) { // <-- file_exists() is affected
  $opened = $zip->open(drupal_realpath($destination));
}
joelpittet’s picture

Thanks for the explaination @haggins. This may be an issue with the public file system as well?

chris burge’s picture

I've been having issues with VBO-generated archives being corrupted prior to download. The patch from #2 corrects this issue.

haggins’s picture

@joelpitt, no there are no problems when you use a public file system as the file will be downloaded directly, ignoring the contents of the file_managed table. The issue just appears on private file systems because Drupal reads the file length from the database and delivers only that amount of bytes to the client.

  • joelpittet committed 71c48a2 on 7.x-3.x authored by haggins
    Issue #2743999 by haggins, joelpittet, hobbsgoblin, Chris Burge: Archive...
joelpittet’s picture

Status: Reviewed & tested by the community » Fixed

I added a bit more documentation around the fix and committed it to -dev. Thanks for explaining the issue further.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.