Edit: this has been almost entirely rewritten as I've narrowed down the issue.

I'm using a Vagrant VM to mirror the client's environment as closely as I can. I'm using VirtualBox 4.3 (with Guest Additions 4.3) with Vagrant 1.3.5, and the server is running CentOS 5.9, Apache 2.2.3-83, PHP 5.3.3, and Drupal 7.

When the server first starts the original files in the shared directory, where my application resides, are cached. When I change the file the original file +/- the filesize delta is served, leading to the image corruption I saw before. So additions add NUL characters on the end of the original, and deletions truncate the file. When I view the file using nano the contents are correct; restarting the httpd service makes no difference. I have to restart the VM for the changes to be served correctly.


// The quick brown fox


// The quick brown fox jumps over the lazy dog

Apache serves:

// The quick brown fox\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0

Where exactly does this error lie? With Apache 2.2 or its dependencies, or with VirtualBox and its Guest Additions?

  • I would download the file from the CentOS box, generate an MD5 checksum and compare that checksum to the original file before it was uploaded (after it was optimized). If they match, then I'd remember that I forgot to clear my browser's cache and do that. If they don't match, I'd generate an MD5 checksum on the file sitting on the CentOS box directly (without downloading). At this point you should be able to figure out where the problem is. If the checksum matches on both the mac and server but not what you download from apache.. the problem is likely either drupal or an apache module. – yoonix Oct 24 '13 at 21:29
  • @yoonix, The way Vagrant works is that it adds a shared directory. I've set this shared directory up, using a symlink, as my web root. So technically, the image is the same both on the Mac and on the VM. But I'll definitely have to double-check my Apache modules; as far as I can tell, Drupal hasn't touched it. – Robert K Oct 25 '13 at 12:57

This is most probably the issue with VirtualBox's buggy sendfile() implementation.

Try setting:

EnableSendfile off

The equivalent for nginx:

sendfile off;
  • This bug cost me half a day and some headaches. This solution solved it. Finally. Thank you. – daniel Mar 4 '15 at 2:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.