6 ms·
This is actually fascinating. I had always imagined (and thought I experienced) that JPGs get corrupted by practically any modification, but it seems most modif
by herpderperator 7y ago
This is actually fascinating. I had always imagined (and thought I experienced) that JPGs get corrupted by practically any modification, but it seems most modifications don't make the image undisplayable, rather only those that mess with the header (for obvious reasons!)
- nneonneo 7y agoThe key is that almost any sequence of bits can be parsed as valid Huffman codes (since unused codes would be a waste of the code space). JPEG doesn’t use any length field for image data, nor does it have any integrity verification. This means you can edit or delete almost any byte in the image data segment and a decoder will still interpret it. A few blocks near the edit site will be corrupted, but it’s very likely that the bitstream will resynchronize some blocks later, so the corruption tends to be highly localized (modulo block/colour component shifting). By contrast, PNG, which also uses Huffman codes for image compression via DEFLATE, has both length fields and integrity checks (CRC32), which the majority of decoders will check. Hence, almost any corruption to a PNG will render it invalid. If you fix up the length and CRC fields after tampering with the file, you can glitch PNGs too, which can produce some very interesting effects.
- mercer 7y agoIt was incredibly fun to see how some changes had drastic effects, but I was also surprised by the fact that most modifications past the header either had no clear visible effect, or kept the image intact. Somehow I'd come to expect otherwise.