10

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.

You
  • 22,800
  • 3
  • 51
  • 64
darrinm
  • 9,117
  • 5
  • 34
  • 34

3 Answers3

12

There is no theoretical maximum, since certain APP markers can be used multiple times (e.g. APP1 is used for both the EXIF header and also the XMP block). Also, there is nothing to prevent multiple comment blocks.

In practice the one that is much more common to result in a large header is specifically the APP2 marker being used to store the ICC color profile for the image. Since some complicated color profiles can be several megabytes, it will actually get split into many APP2 blocks (since each APP block one has a 16bit addressing limit).

Grayson Lang
  • 156
  • 1
  • 5
6

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
  • 175
  • 3
  • 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 Jul 15 '10 at 23:08
  • 3
    Grayson Lang's answer is the correct one. There is nothing to prevent multiple blocks of the same marker. – Yoav Mar 19 '14 at 07:26
  • on linux, the wrjpgcom and rdjpgcom tools are extremely useful... this is where I ended up pushing a lot of text data. – phyatt Mar 16 '17 at 15:18
3

Wikipedia states:

Exif metadata are restricted in size to 64 kB in JPEG images because according to the specification this information must be contained within a single JPEG APP1 segment.

gsamaras
  • 71,951
  • 46
  • 188
  • 305