Pack arbitrary files into PNG and access them using JavaScript
github.com
github.com
Cody's goal was to compress already minified WebGL code and achieve some pretty impressive results from a ridiculously small file for a demo contest. He also put the JS loader (which is much smaller than the linked decoder) in a custom chunk on the PNG itself. By doing it that way, you can have a PNG that when renamed also contains a web page and/or more Javascript.
It's an interesting technique, for sure, but I've never been able to find a real use for it beyond the compression. With a content-type sniffing vulnerability or something, it could be an interesting way to deliver content to browsers, but otherwise it's really just a curiosity as best I can tell.
``` jawh<img onload=with(document.createElement('canvas'))p=width=4968,(c=getContext('2d')).drawImage(this,e='',0);while(p)e+=String.fromCharCode(c.getImageData(0,0,p,1).data[p-=4]);(t=top).eval(e) src=#> ```
https://github.com/mnutt/hid.im/blob/master/public/firefox-e...
>JPG & PNG Steganography Encoder (JPG-PNGStega). The purpose of this encoder is to inject data (hiding it) in JPG and PNG files. It takes a File Format Sample (JPG or PNG) and, for each pixel, it injects 3 bits of data in the LSBs (Least Significant Bit). There are more sophisticated image steganography methods already widely discussed. However, the use of this encoder shows that even basic meth- ods of JPG and PNG steganography are possible in SaaS applications, and the exploitation of such method may bring impacts
But you run the risk of a ToS violating, losing your files and having your account banned.
Though that's still kind of an odd use case, since we have gzip encoding for that.
I could be wrong, but doesn't that work?
Also, I wonder how difficult it would be to port a decompression library to asm.js.
The need appeared when I was doing my WebGL game engine and wanted to pack/compress mesh, texture, xml and any other stuff that would bloat my loading time with tons of HTTP requests!
Also the browser's native PNG decompression would be faster than any external JS lib for lossless decompression.
I limited it to a 16k x 16k PNG (but I think modern browsers can take more than that), allowing 1GB of data.
I wonder how true this holds with HTTP/2.0, where resources are loaded in parallel over a single TCP connection.