Commit 39e0d432 authored by Noam Rosenthal's avatar Noam Rosenthal Committed by Commit Bot

JPEG decoder: Reading offsets from EXIF was off by two bytes.

For rational numbers this worked OK by chance when both the nominator and
the denominator were < 65536, because the error was cancelled by the
division. However, this doesn't work when the nominator/denominator are
larger than 65535.

Fixed the offset, and added a test with large nom/denom.

Bug: 1143645
Change-Id: Ic8e46c580437fb4585197807c89a48f43435852a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2507110Reviewed-by: default avatarStephen Chenney <schenney@chromium.org>
Commit-Queue: Stephen Chenney <schenney@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822179}
parent c02b321d
......@@ -315,7 +315,7 @@ static void ReadExifDirectory(JOCTET* dir_start,
kOrientationTag = 0x112,
kResolutionXTag = 0x11a,
kResolutionYTag = 0x11b,
kresolution_unitTag = 0x128,
kResolutionUnitTag = 0x128,
kPixelXDimensionTag = 0xa002,
kPixelYDimensionTag = 0xa003,
kExifOffsetTag = 0x8769
......@@ -353,7 +353,7 @@ static void ReadExifDirectory(JOCTET* dir_start,
metadata.orientation = ImageOrientation::FromEXIFValue(ReadUint16(value_ptr, is_big_endian));
break;
case ExifTags::kresolution_unitTag:
case ExifTags::kResolutionUnitTag:
if (type == kUnsignedShortType && count == 1)
metadata.resolution_unit = ReadUint16(value_ptr, is_big_endian);
break;
......@@ -431,7 +431,7 @@ static void ReadImageMetaData(jpeg_decompress_struct* info, DecodedImageMetaData
// http://partners.adobe.com/public/developer/en/tiff/TIFF6.pdf
JOCTET* data_end = marker->data + marker->data_length;
JOCTET* root_start = marker->data + kOffsetToTiffData;
JOCTET* tiff_start = marker->data + ifd_offset;
JOCTET* tiff_start = marker->data + ifd_offset - 2;
JOCTET* ifd0 = root_start + ifd_offset;
ReadExifDirectory(ifd0, tiff_start, root_start, data_end, is_big_endian, metadata);
......
......@@ -23,6 +23,7 @@
await test_valid({width: 10, height: 20, preferredWidth: 20, preferredHeight: 10, resolutionX: 36, resolutionY: 144, resolutionUnit: 2})
await test_valid({width: 10, height: 20, preferredWidth: 10, preferredHeight: 40, resolutionX: 72, resolutionY: 36, resolutionUnit: 2})
await test_valid({width: 30, height: 30, preferredWidth: 90, preferredHeight: 30, resolutionX: 24, resolutionY: 72, resolutionUnit: 2})
await test_valid({width: 10, height: 20, preferredWidth: 20, preferredHeight: 40, resolutionX: [72 * 1000000, 2 * 1000000], resolutionY: [72 * 10000000, 2 * 10000000], resolutionUnit: 2})
await test_invalid({width: 10, height: 20, preferredWidth: 20, preferredHeight: 30, resolutionX: 36, resolutionY: 36, resolutionUnit: 2})
await test_invalid({width: 10, height: 20, preferredWidth: 33, preferredHeight: 40, resolutionX: 36, resolutionY: 36, resolutionUnit: 2})
......
......@@ -20,9 +20,9 @@ function createImageWithMetadata({
if (orientation !== undefined)
root[piexif.ExifIFD.Orientation] = orientation
if (resolutionX !== undefined)
root[piexif.ImageIFD.XResolution] = [resolutionX, 1]
root[piexif.ImageIFD.XResolution] = Array.isArray(resolutionX) ? resolutionX : [resolutionX, 1]
if (resolutionY !== undefined)
root[piexif.ImageIFD.YResolution] = [resolutionY, 1]
root[piexif.ImageIFD.YResolution] = Array.isArray(resolutionY) ? resolutionY : [resolutionY, 1]
if (resolutionUnit !== undefined)
root[piexif.ImageIFD.ResolutionUnit] = resolutionUnit
if (preferredWidth !== undefined)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment