A file that’s both an acceptable HTML page and a JPEG (2012)
lcamtuf.coredump.cx
lcamtuf.coredump.cx
He bundled the whole source code and binary data used in the game/tech demo to use the in browser image decompression, avoiding to write a custom (de)compression code, saving KBs this way.
Then he just eval() the needed parts for each thing.
I found this extremely clever, game jam limitations, specially size ones, evolve into clever programming tricks that are interesting both to code and to look at.
You definitely won't save enough bytes with better input heuristics than the amount of code needed to decompress them if you're only working with 13Kb of data.
Each of the possible filters is very simple, but the difference between a great PNG exporter, a mediocre one, and a trash fire is the use of a heuristic to decide which of the pre-processing filters should be applied to each line of output. libpng, the free implementation, includes a heuristic that does a fairly OK job, if you just don't implement a heuristic and use no filtering at all, the results are enormous PNG files as seen in turn of the century Adobe Photoshop. So, no, a general purpose compression algorithm isn't very good for image data on its own.
(Choose for yourself whether you think Adobe wanted to discourage use of a popular free image format in favour of licensed formats for which it held relevant IP, or their development team are just incompetent morons, or both).
Yes, as a means of making the data fed into the compressor repetitive enough to benefit from the compression algorithm.
> So, no, a general purpose compression algorithm isn't very good for image data on its own.
That's not what I said.
I am not really into javascript/frontend development, but following js13k on twitter showed me a lot of things you can do to gain KBs on the client side.
However, is this that common?
Thanks for the info btw.
Also of note, klange's unofficial résumé in C https://gist.github.com/klange/4042963
If anyone's interested in what these are called, they are called polygots.
> In computing, a polyglot is a computer program or script written in a valid form of multiple programming languages, which performs the same operations or output independent of the programming language used to compile or interpret it.
1. JPEG allows text comments
2. Browsers don't enforce correct HTML (alternatively, is "����JFIF,,��r<html>" correct HTML?)
3. And exif tools mostly work based on header & statistical analysis?
Or am I completely wrong here?
I'd like to build a system for distributing mini-apps as images, bypassing the App Store.
A JavaScript bookmarklet could be used to provide a basic "bootloader" that provides an "upload image" button. Then a binary representation of the HTML could be loaded from the image data.
The problem I had was lossy recompression - colours bleed across edges, so the binary data was corrupt after the first save. I'm still not sure how to work around that problem.
https://www.alchemistowl.org/pocorgtfo/
https://www.alchemistowl.org/pocorgtfo/pocorgtfo07.pdf
6 Abusing file formats; or, Corkami, the Novella by Ange Albertini
And more example/pocs:
# exiftool -b -comment <(curl -s http://lcamtuf.coredump.cx/squirrel/)
<html><body><style>body { visibility: hidden; } .n { visibility: visible; position: absolute; padding: 0 1ex 0 1ex; margin: 0; top: 0; left: 0; } h1 { margin-top: 0.4ex; margin-bottom: 0.8ex; }</style><div class=n><h1><i>Hello, squirrel fans!</i></h1>This is an embedded landing page for an image. You can link to this URL and get the HTML document you are viewing right now (soon to include essential squirrel facts); or embed the exact same URL as an image on your own squirrel-themed page:<p><xmp><a href="http://lcamtuf.coredump.cx/squirrel/">Click here!</a></xmp><xmp><img src="http://lcamtuf.coredump.cx/squirrel/"></xmp><p>No server-side hacks involved - the magic happens in your browser. Let's try embedding the current page as an image right now (INCEPTION!):<p><img src="#" style="border: 1px solid crimson"><p>Pretty radical, eh? Send money to: lcamtuf@coredump.cx<!--Yes, it shows up as all green in Safari. And:
$ { curl -s http://lcamtuf.coredump.cx/squirrel/?1 | grep -- '-->' ; } || echo "Not found"
Not found JPEG image data, JFIF standard 1.01, resolution (DPI), density 300x300, segment length 16, comment: "<html><body><style>body { visibility: hidden; } .n { visibility: visible; position: absolute; ", baseline, precision 8, 1000x667, frames 3 squirrel: HTML document, ASCII text
BSD file(1) on both Linux and NetBSD. Solaris also identifies it as HTML. $ curl -s http://lcamtuf.coredump.cx/squirrel/ | file -
/dev/stdin: JPEG image data, JFIF standard 1.01, resolution (DPI), density 300x300, segment length 16, comment: "<html><body><style>body { visibility: hidden; } .n { visibility: visible; position: absolute; ", baseline, precision 8, 1000x667, frames 3
file(1) version 5.32-2ubuntu0.1.so you get even more details...
From section 8:
"A careful reader may have noticed that a bootable OS image was hidden in the last issue of PoC k GTFO, as one of the files in its dual PDF/ZIP structure (if you haven’t, download and extract it now!). This time, though, let’s hide it in plain sight. You will find by running ‘qemu-system-i386 -fda pocorgtfo02.pdf’ that the PDF file you are reading is also a bootable disk image."
https://greatscottgadgets.com/pocorgtfo/pocorgtfo02.pdf
And issue 3:
"This file, pocorgtfo03.pdf, complies with the PDF, JPEG, and ZIP file formats. When encrypted with AES in CBC mode with an IV of 5B F0 15 E2 04 8C E3 D3 8C 3A 97 E7 8B 79 5B C1 and a key of “Manul Laphroaig!”, it becomes a valid PNG file. Treated as single-channel raw audio, 16-bit signed little-endian integer, at a sample rate of 22,050 Hz, it contains a 2400 baud AFSK transmission."
(TLDR, Chipmunks are not Squirrels)
> Squirrels are members of the family Sciuridae, a family that includes small or medium-size rodents. The squirrel family includes tree squirrels, ground squirrels, chipmunks, marmots (including woodchucks), flying squirrels, and prairie dogs amongst other rodents.
(TLDR, chipmunks are squirrels)
> Marmots are large squirrels
It's a PNG that's interpreted as HTML and loads itself as compressed JavaScript!
So, literally copying previous top comments on old posts is now a popular thing?
It seems to have been a one-off, so we won't ban the account.