Skip to content

exif: ensure prefix is present before parsing #3100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2022

Conversation

lovell
Copy link
Member

@lovell lovell commented Oct 19, 2022

It looks like some newer Apple devices are attaching EXIF to images without the Exif\0\0 prefix, however libexif still requires it due to JPEG/JFIF/APP1 marker heritage.

There's an upstream issue about this at libexif/libexif#58

Originally reported at lovell/sharp#3412

Before:

exif-data: 2402 bytes of binary data
exif-ifd0-XResolution: 72009/1000 (72.009, Rational, 1 components, 8 bytes)
exif-ifd0-YResolution: 72009/1000 (72.009, Rational, 1 components, 8 bytes)
exif-ifd0-ResolutionUnit: 2 (Inch, Short, 1 components, 2 bytes)
exif-ifd2-ExifVersion: Exif Version 2.1 (Exif Version 2.1, Undefined, 4 components, 4 bytes)
exif-ifd2-FlashpixVersion: FlashPix Version 1.0 (FlashPix Version 1.0, Undefined, 4 components, 4 bytes)
exif-ifd2-ColorSpace: 65535 (Uncalibrated, Short, 1 components, 2 bytes)

After:

exif-data: 2402 bytes of binary data
exif-ifd0-Make: Apple (Apple, ASCII, 6 components, 6 bytes)
exif-ifd0-Model: iPhone 11 Pro Max (iPhone 11 Pro Max, ASCII, 18 components, 18 bytes)
exif-ifd0-Orientation: 1 (Top-left, Short, 1 components, 2 bytes)
exif-ifd0-XResolution: 72/1 (72, Rational, 1 components, 8 bytes)
exif-ifd0-YResolution: 72/1 (72, Rational, 1 components, 8 bytes)
exif-ifd0-ResolutionUnit: 2 (Inch, Short, 1 components, 2 bytes)
exif-ifd0-Software: 15.5 (15.5, ASCII, 5 components, 5 bytes)
exif-ifd0-DateTime: 2022:07:08 13:00:46 (2022:07:08 13:00:46, ASCII, 20 components, 20 bytes)
exif-ifd2-ExposureTime: 1/122 (1/122 sec., Rational, 1 components, 8 bytes)
exif-ifd2-FNumber: 12/5 (f/2.4, Rational, 1 components, 8 bytes)
exif-ifd2-ExposureProgram: 2 (Normal programme, Short, 1 components, 2 bytes)
exif-ifd2-ISOSpeedRatings: 25 (25, Short, 1 components, 2 bytes)
exif-ifd2-ExifVersion: Exif Version 2.32 (Exif Version 2.32, Undefined, 4 components, 4 bytes)
exif-ifd2-DateTimeOriginal: 2022:07:08 13:00:46 (2022:07:08 13:00:46, ASCII, 20 components, 20 bytes)
exif-ifd2-DateTimeDigitized: 2022:07:08 13:00:46 (2022:07:08 13:00:46, ASCII, 20 components, 20 bytes)
exif-ifd2-OffsetTime: +01:00 (+01:00, ASCII, 7 components, 7 bytes)
exif-ifd2-OffsetTimeOriginal: +01:00 (+01:00, ASCII, 7 components, 7 bytes)
exif-ifd2-OffsetTimeDigitized: +01:00 (+01:00, ASCII, 7 components, 7 bytes)
exif-ifd2-ComponentsConfiguration: Y Cb Cr - (Y Cb Cr -, Undefined, 4 components, 4 bytes)
exif-ifd2-ShutterSpeedValue: 68321/9857 (6.93 EV (1/122 sec.), SRational, 1 components, 8 bytes)
exif-ifd2-ApertureValue: 4845/1918 (2.53 EV (f/2.4), Rational, 1 components, 8 bytes)
exif-ifd2-BrightnessValue: 35212/4987 (7.06 EV (457.43 cd/m^2), SRational, 1 components, 8 bytes)
exif-ifd2-ExposureBiasValue: 0/1 (0.00 EV, SRational, 1 components, 8 bytes)
exif-ifd2-MeteringMode: 5 (Pattern, Short, 1 components, 2 bytes)
exif-ifd2-Flash: 16 (Flash did not fire, compulsory flash mode, Short, 1 components, 2 bytes)
exif-ifd2-FocalLength: 77/50 (1.5 mm, Rational, 1 components, 8 bytes)
exif-ifd2-SubjectArea: 2015 1511 2324 1392 (Within rectangle (width 2324, height 1392) around (x,y) = (2015,1511), Short, 4 components, 8 bytes)
exif-ifd2-MakerNote: 1236 bytes undefined data (1236 bytes undefined data, Undefined, 1236 components, 1236 bytes)
exif-ifd2-SubsecTime: 520 (520, ASCII, 4 components, 4 bytes)
exif-ifd2-SubSecTimeOriginal: 520 (520, ASCII, 4 components, 4 bytes)
exif-ifd2-SubSecTimeDigitized: 520 (520, ASCII, 4 components, 4 bytes)
exif-ifd2-FlashpixVersion: FlashPix Version 1.0 (FlashPix Version 1.0, Undefined, 4 components, 4 bytes)
exif-ifd2-ColorSpace: 1 (sRGB, Short, 1 components, 2 bytes)
exif-ifd2-PixelXDimension: 288 (288, Long, 1 components, 4 bytes)
exif-ifd2-PixelYDimension: 279 (279, Long, 1 components, 4 bytes)
exif-ifd2-SensingMethod: 2 (One-chip colour area sensor, Short, 1 components, 2 bytes)
exif-ifd2-SceneType: Directly photographed (Directly photographed, Undefined, 1 components, 1 bytes)
exif-ifd2-ExposureMode: 0 (Auto exposure, Short, 1 components, 2 bytes)
exif-ifd2-WhiteBalance: 0 (Auto white balance, Short, 1 components, 2 bytes)
exif-ifd2-DigitalZoomRatio: 1512/1325 (1.1411, Rational, 1 components, 8 bytes)
exif-ifd2-FocalLengthIn35mmFilm: 15 (15, Short, 1 components, 2 bytes)
exif-ifd2-SceneCaptureType: 0 (Standard, Short, 1 components, 2 bytes)
exif-ifd2-LensSpecification: 807365/524263 6/1 9/5 12/5 (1.540000,  6, 1.8, 2.4, Rational, 4 components, 32 bytes)
exif-ifd2-LensMake: Apple (Apple, ASCII, 6 components, 6 bytes)
exif-ifd2-LensModel: iPhone 11 Pro Max back triple camera 1.54mm f/2.4 (iPhone 11 Pro Max back triple camera 1.54mm f/2.4, ASCII, 50 components, 50 bytes)
exif-ifd2-CompositeImage: 2 (2, Short, 1 components, 2 bytes)
exif-ifd3-GPSLatitudeRef: N (N, ASCII, 2 components, 2 bytes)
exif-ifd3-GPSLatitude: 55/1 14/1 2461/100 (55, 14, 24.61, Rational, 3 components, 24 bytes)
exif-ifd3-GPSLongitudeRef: W (W, ASCII, 2 components, 2 bytes)
exif-ifd3-GPSLongitude: 6/1 30/1 3820/100 ( 6, 30, 38.20, Rational, 3 components, 24 bytes)
exif-ifd3-GPSAltitudeRef: Sea level (Sea level, Byte, 1 components, 1 bytes)
exif-ifd3-GPSAltitude: 52037/8161 (6.3763, Rational, 1 components, 8 bytes)
exif-ifd3-GPSSpeedRef: K (K, ASCII, 2 components, 2 bytes)
exif-ifd3-GPSSpeed: 0/1 ( 0, Rational, 1 components, 8 bytes)
exif-ifd3-GPSImgDirectionRef: T (T, ASCII, 2 components, 2 bytes)
exif-ifd3-GPSImgDirection: 130663/487 (268.302, Rational, 1 components, 8 bytes)
exif-ifd3-GPSDestBearingRef: T (T, ASCII, 2 components, 2 bytes)
exif-ifd3-GPSDestBearing: 130663/487 (268.302, Rational, 1 components, 8 bytes)
exif-ifd3-GPSHPositioningError: 7566/1549 (4.8844, Rational, 1 components, 8 bytes)

Newer Apple devices are creating EXIF without this however libexif
still requires it due to JPEG/JFIF/APP1 marker heritage.
@jcupitt
Copy link
Member

jcupitt commented Oct 19, 2022

Nice! I merged to master as well.

@lovell lovell deleted the exif-ensure-prefix branch October 19, 2022 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants