Skip to content

JPEG-hul fails to parse valid Apple Multi-Picture Format file #1051

@Kris-LIBIS

Description

@Kris-LIBIS

When I run JHove on a valid JPEG, created by an iPhone dual camera, an error is thrown and the file is marked as not well-formed.

This is the JHove output:

➜ jhove -m JPEG-HUL IMG_1616.jpg 
Jhove (Rel. 1.32.0, 2024-09-12)
 Date: 2025-07-04 00:13:27 CEST
 RepresentationInformation: IMG_1616.jpg
  ReportingModule: JPEG-hul, Rel. 1.5.4 (2023-03-16)
  LastModified: 2025-07-04 00:12:54 CEST
  Size: 3723240
  Format: JPEG
  Version: 1.01
  Status: Not well-formed
  SignatureMatches:
   JPEG-hul
  ErrorMessage: Expected marker byte 255 : Read marker byte value 65 
   ID: JPEG-HUL-7
   Offset: 21
  MIMEtype: image/jpeg

On this sample image: https://www.jianguoyun.com/p/DZou8ewQgsqOBxjb-Ho

Below is a screenshot of the hex-editor of the first few bytes:

Image

APP0 starts at position 0x02 with marker '0xFF 0xE0' => OK
next word is at 0x04 -> 0x14 = 20 => OK
So next section is APP1 at postition 0x04 + 0x14 = 0x18, '0xFF 0xE1' => OK

But JHove starts reading the section at offset 21 (0x14) => Not OK

I found the code at

skipBytes(_dstream, 3 * xThumbPix * yThumbPix, this);
does not take the length value into account and asumes that the APP0 always ends when the thumbnail data is read. The JPEG-hul should skip any extra bytes in the APP0 section until it has consumed all 'length' bytes.

Apparently, in this case Apple has added the 4 bytes 'A', 'M', 'P', 'F' to the end of the regular APP0 and added 4 to the length value of the APP0. This makes this JPEG a bit special, but still well-formed.

See also the remark in the ExifTools code at https://github.com/exiftool/exiftool/blob/a755221b7937406a16b40bcd533e992aa8b5caa0/lib/Image/ExifTool.pm#L2251

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions