Philip Jacob

MSIE hangs when trying to load .jpg images

· Philip Jacob

Bea recently started getting complaints from her blog readers that they couldn’t see the images on her site. I thought that it was strange that neither of us would have noticed this, but sure enough, they were right. The problem was infuriatingly difficult to debug, so I figured that I would post my fix here. But I was lucky: I wasted an entire weekend on this exact problem about 3 years ago, so I had a sense of what I was looking for after I remembered the details.

The symptom is this: MSIE on Windows stops loading graphics. Everything else loads fine, but the graphics just refused to load. You can sniff packets, look at HTTP headers and everything will be normal. But broken at the same time.

Basically, certain applications on the Mac platform (like Photoshop) put large quantities of XML into the header of .jpg images. The XML looks like this:


Whenever MSIE encounters one of these large XML chunks in a jpg, all images from then on will not load until the browser is restarted. So it’s like a tripwire: once you set it off, everything breaks.

The fix? Well, I used a few lines of perl and some netpbm utilities. Make a file with all of the offending images and feed it to this script:

#!/usr/bin/perl -w

use strict;

open (F, "/tmp/bad-images.txt");
while () {
my $file = $_;
print $file, "n";

$file =~ s/(/(/g;
$file =~ s/)/)/g;
$file =~ s/ / /g;

my $command = "cp $file /tmp/ && anytopnm $file | pnmtojpeg > $file.2 && mv $file.2 $file";


If you’re going to have any luck with this, you’ll probably be running on some kind of Unix server with netpbm installed.

There’s some more info on this article.