Today we're ran into a rather obscure situation. Rosyna has created a bz2-compressed DMG image for the new beta of the next major update to FontCard, and when I went to download it, I've noticed that Safari downloads it as "fontcard-xxx.dmg.bz2". Needless to say, it tried to expand the bz2 file upon downloading, and then failed miserably on mounting the expanded DMG file with this error:

"WTF?", I thought. The file name in the URL was ending with "dmg" and not "dmg.bz2". Yes, the data inside of the DMG is compressed using bz2, but nobody should care about that.
So I tried to download the same file using FireFox, and all went just fine: the image downloaded, the file name never changed, and it mounted as it should. I've looked at the response our server been sending, and it was:
Content-Type: application/octet-stream
So what I am guessing is that Safari tries to guess the file type when it's not forcibly defined by the Content-Type; in this particular case, it looked in the file and noticed it is most likely a bz2 archive, so it safely appended the .bz2 extension to the file and continued the download, resulting in the hiatus described above.
So, we've made a tiny change to our .htaccess file, and guess what? Now all DMGs (including the one I just had problems with) download just fine. This also possibly explains why some of our users were having random issues with the DMG images they've downloaded. Perhaps in some cases Safari decided it's a zip archive (since we used to prepare our DMGs compressed with zip), expanding it before passing to the diskutil, making it fail in the end.
So, if you serve DMGs off your hosting, take a note on that. Luckily, the fix is simple (assuming your web host uses Apache):
Open or create a .htaccess file in the root of your Web directory, and put the following line in:
AddType application/x-apple-diskimage dmg
This instructs Apache to forcibly tell the visitors that files ending with "dmg" has a content type of application/x-apple-diskimage, which makes Safari behave as it should: skip the "guessing" part and pass the image where it belongs.
I'd like to say thanks to Mark Rowe for telling us the "right" MIME type. ;)
Related:
- Betas, Twitter and WTF - Feb 16, 2010
- Quick Status Update - Feb 12, 2010
- It's Winter, Right? - Jan 26, 2010
- Hiya Kids, it's Theming Time! - Oct 06, 2009
- Mighty Mouse with Some Theme Sauce - Jun 02, 2009
Interesting, I had a big problem with this myself with Quicksilver. http://getqs.com downloads a .dmg.bz2 image for me in Safari, but not in Camino or Firefox. I read about the fix on Macupdate, but it still isn't fixed.
Posted by: ACoolie on May 17, 2007 1:10 PMhiatus
a pause or gap in a sequence, series, or process
Suggested alternatives:
- hubbub
- hustle
- havoc
—————
On another note, thanks for posting this. It'll come in handy if I ever find myself serving DMG files.
Posted by: Arden on May 19, 2007 5:33 PMHow can I get FruitMenu to show my real world IP address? Instead of 10.0.1.1 in my Apple Menu?
Posted by: Court Kizer on May 22, 2007 7:58 PMI think I saw this same problem with the SourceForge download of the latest aMSN distribution. I'd thought they were just out of their vulcan minds and for some reason decided to distribute aMSN as a dmg.bz2 ;) (I have my Safari set not to auto-open things and so was just left with a dmg.bz2 file in the Finer. Of course, BOMArchive helper refused to decompress it.
Going to FireFox solved the problem of course so I never thought of it again until now.
Thanks for posting this useful stuff.
-Ken
Has anyone used the .htaccess trick on .Mac? I created one in my Sites folder (which I point to as a backup server). While I have never seen this bug, a user reports there's still a problem.
Posted by: David Dunham on June 1, 2008 8:56 PMI've only seen users of The Unarchiver running into this issue. I've been in contact with the developer and it IS a Mac OS bug, but doesn't show itself on a default OS X install. Some of the file types that The Unarchiver registers to handle give Safari extra options for identifying files, and it incorrectly identifies some disk images (maybe ones with bzip2 compression) as tar+bzip2 archives.
You can work around the problem by opening The Unarchiver preferences and unchecking "Bzip2 Tar Archive" in its list of archive formats.
Posted by: Sidney San Martín on June 2, 2009 8:15 AM