Live data from Hacker News

A file that's both an acceptable HTML page and a JPEG (view source on it)

lcamtuf.coredump.cx

1–10 of 133 posts

Re: A file that's both an acceptable HTML page and a JPEG (view source on it)

#7
post #4
post #2

Can someone explain what is going on here?

view source shows that he has an html document embedded in the jpeg. Apparently, the jpeg format allows this.

JPEG allows for additional data chunks (that's how thumbnails, EXIF data, ... are added). The HTML uses CSS to hide the "body" (since that would include the JPEG header), putting the real content in a container element that poses as new root.

Neat hack.

Re: A file that's both an acceptable HTML page and a JPEG (view source on it)

#8
post #2

Can someone explain what is going on here?

Web browsers need to be very loose in how they interpret data for historical reasons. A lot of this is even codified in the current HTML standard, like always content-sniffing images and identifying data that can be ignored during parsing. You also have HTML comments, which is where most of the JPEG data is packed in this example. Combine that with the fact that image formats generally allow you to pack comments or other arbitrary metadata into fields, and you end up with a file that can be read as either a JPEG or HTML. Also, Michal has a weird thing for squirrels.

Re: A file that's both an acceptable HTML page and a JPEG (view source on it)

#9
post #4
post #2

Can someone explain what is going on here?

view source shows that he has an html document embedded in the jpeg. Apparently, the jpeg format allows this.

The HTML document is in the "comment" field of the JPEG, which is perfectly reasonable.

What is surprising is that web browsers just ignore the 24 bytes of binary data between the start of the file and the start of the HTML.

Re: A file that's both an acceptable HTML page and a JPEG (view source on it)

#10
post #2

Can someone explain what is going on here?

The file has been created in such a way that the web browser is ignoring the non-html parts of the document, while the image renderer is ignoring the parts that make up the html page.

The first part probably isn't too hard, since most web browsers go to great lengths to render non-standard html in a sensible way, I'm not too sure about the second part. I'm guessing the jpeg spec has some variable length space in some kind of file header that the html for the page can be put in to.

I read something similar a while back (I think it was called a Jafar attack) where a clever person worked out how to create a file that was both a valid .gif image and .jar java executable.

Post reply on HN