views:

36

answers:

1

Is there a theoretical maximum to the amount of metadata (EXIF, etc) that can be incorporated in a JPEG file? I'd like to allocate a buffer that is assured to be sufficient to hold the metadata for any JPEG image without having to parse it myself.

A: 

Each APPN data area has a length field that is 2 bytes, so 65536 would hold the biggest one. If you are just worried about the EXIF data, it would be a bit less.
http://www.fileformat.info/format/jpeg/egff.htm There are at most 16 different APPN markers in a single file. I don't think they can be repeated, so 16*65K should be the theoretical max.

edgman
Thanks edgman. It looks like some of the markers are effectively fixed to lengths less than 64K so a lower theoretical bound could be calculated but your rough calculation is good enough for my purposes.
darrinm