News for hackers. Stuff that matters.
Re:You Don't Know GIF – An analysis of a GIF file and some w... by bawolff on Friday March 11, 2022 @05:07AM (#30638192)
Once upon a time i wrote some code to display metadata for gif files that were uploaded to wikipedia.

My favorite part of gif is the hack to embed XMP metadata into gif files. XMP is supposed to be valid xml (it is adobe's rdf based image metadata standard), and should be readable even by format unaware readers. However gif metadata is supposed to be split into (up to) 255 byte blocks where you do 1 byte length, followed by that many bytes of data, another length byte + data, until you terminate with a null byte for a zero length data segment.

This of course is incompatible with making valid xml. However nulls are invalid in xml, so what the spec makers did instead was to ignore these length bytes, just put the xml in without changing it, but end the section with <FF>, <FE>, .... <01>, <00> as a sort of NOP slide-esque thing, in order to make sure everything is well formed acording to the gif standard. If your parsing the file like a normal gif eventually you will jump into the end segment, and everything will be well formed. Its just such an interesting hack to meet all requirements.

Of course, i'm not sure anyone actually creates gif files with metadata so may be a bit moot in practice.

There are no comments on this comment yet.