Commit Graph

108 Commits

Author SHA1 Message Date
Chong Zhang
64eeef77ee Fix failure in ExifInterface on certain HEIF files
Some sniffers in MediaExtractor might issue reads past the end of
the file. This results in IOException in our MediaDataSource. The
exception itself is not fatal, but need to make sure MediaDataSource
state is kept in sync otherwise the other extractors can't continue.

Bug: 79497983
Test: test the ExifInterface on the attached file in bug, as well as
      selected HEIF files from other devices, Exif should be extracted
      without error in the log.

Change-Id: I5c8f597b8ef14288e3465670b202adc93c09e6ea
2018-05-09 18:52:01 -07:00
TreeHugger Robot
6cc4575ced Merge "ExifInterface: Prevent infinite loop" into pi-dev 2018-04-20 02:43:54 +00:00
Jin Seok Park
12e7aa5882 ExifInterface: Prevent infinite loop
A corrupted image file may create two problems.
1. A corrupted IFD pointer may point to an IFD that has already
been read, thus creating an infinite loop and a stack overflow.
2. A corrupted IFD offset value may have a negative value, thus
prompting a random reading of the file and creating an infinite
loop.
This CL addresses these issues.

Bug: 63800695
Test: Run cts (ExifInterfaceTest)
Change-Id: I706a0c3eae6af8301af69407333ea88e5681df3c
2018-04-20 10:36:00 +09:00
Chong Zhang
2cc0a2eca9 Extract exif data from mp4 extractor if available
Query the extractor for the exif data offset and length,
if it's available, read the exif block from the file.
Otherwise, set image dimension and rotation only.

bug: 76149934

Change-Id: I85f24b526fb356a9227941e20807fc96369c8536
2018-04-05 11:25:45 -07:00
Jin Seok Park
473201868c ExifInterface: Remove casting int[] to long[]
This CL removes code that directly casts int[] to long[] and instead
iterates through the individual values and casts to int if necessary.
They are cast to integer because StripOffsets/StripByteCounts
Attributes can return either int[] or long[] values, but the maximum
length of a file that ExifInterface can handle is the maximum value
of integer, so it should be safe to cast the long values to integer
values.

Bug: 73091048
Test: Cts
Change-Id: I9f3b98204e0829a8a8a30927bb8c0a698c457654
2018-03-27 14:58:52 +09:00
Chong Zhang
869d1234d6 ExifInterface: prefer metadata from image track
If the file has both image and video, prefer image info over
video info. App querying ExifInterface is most likely using
the bitmap path which picks the image first.

bug: 63633199

Test:
tested querying the rotation info in own test app.

Change-Id: I955b27c2ad699d4895e171053ea27b62e779db2b
2017-10-31 12:28:22 -07:00
Chong Zhang
7a5469865b Merge "Use rotation from MediaMetadataRetriever directly" into oc-mr1-dev am: 106aeb324d
am: 0764ce28cf

Change-Id: I59a84542c4cfc2cb48627396642dd2d4bbdc2291
2017-10-06 05:39:50 +00:00
Chong Zhang
9af92dadc9 Use rotation from MediaMetadataRetriever directly
MediaMetadataRetriever now reports rotation in clockwise,
no longer need to translate.

bug: 67470228

Test: verified rotation using test app attached in bug
Change-Id: Ifebcf25ea302477818e2e03db1e55525db985e67
2017-10-05 15:13:54 -07:00
Chong Zhang
c658124d50 Merge "Add heif format to ExifInterface" into oc-mr1-dev am: e034a1f5ed
am: 3985765a17

Change-Id: I1cb5527a9bb1a63cb960cbc7d38aa955353a28c9
2017-08-31 03:36:24 +00:00
Chong Zhang
6f80587e8b Add heif format to ExifInterface
Get heif dimension and rotation from MediaMetadataRetriever.

Bug: 64077740
Change-Id: I711ac70d356dbfd9128a30ab33c0dfd81a4ae17e
2017-08-30 11:33:07 -07:00
Jin Seok Park
4ae72e6cbf Merge "ExifInterface: Remove throwing exception" into oc-mr1-dev am: 48dad606c5
am: a0e00f5015

Change-Id: I03db88b452431a3ec454754bbb7eb99a43ee0356
2017-08-04 01:05:01 +00:00
Jin Park
d113478931 ExifInterface: Remove throwing exception
ExifInterface reads the first 5000 bytes of an image file to
determine what type of image it is, and throws an EOFException
if the file is smaller 5000 bytes. This CL removes the throwing
action.

Bug: 64133582
Test: Run ExifInterfaceTest.java with <5kb file
Change-Id: I2b2026f06d70a4fe2986d2e8c410679ba9bf3f7f
2017-08-02 08:48:17 +00:00
Julian Mancini
a83cc4582f Add support for simpler Lat/Long values
In this CL, we add two public static final Strings to MetadataReader. I
use these to put in an "extras" bundle into our highest level bundle.
Within that extras bundle is the Latitude and Longitude values, if
available.

Bug: 63906073
Test: In Place
Change-Id: I1feccb4444d6525f9bc8bddfe8cc73b098e0b90e
2017-07-27 10:21:23 -07:00
Hyundo Moon
9442e11470 ExifInterface: Prevent DATETIME value from being set unproperly
Although the DATETIME and DATETIME_ORIGINAL tags are for different
purposes, the DATETIME value is set to the same value as
DATETIME_ORIGINAL tag's when loading the attributes of an image.
This CL prevents the problem by setting the value of DATETIME tag only
when it does not exist.

Bug: 62137632
Test: Passed ExifInterface CTS
Change-Id: Ic5c43c53cb363a782bcac20915d74ea534ec70e4
2017-06-13 02:37:20 +00:00
Hyundo Moon
4564cbceb4 ExifInterface: Correct thumbnail compression info
Exifinterface sets the thumbnail's compression information as JPEG
whenever the image has no compression tag in it. As a result, even
an image with no thumbnail can have the thumbnail compression info.
This CL fixes the problem.

Test: Run CTS test on angler
Change-Id: I4b06956b1bac672e1bf235df6f458b31e8ee82bb
2017-03-10 19:15:05 +09:00
Hyundo Moon
644e1375e8 ExifInterface: Accept decimal values for RATIONAL formats
Prior to android N, ExifInterface.setAttributes() accepted the
decimal values for SRATIONAL/URATIONAL formats. However in android N,
decimal values for RATIONAL formats are rejected. Since this behavior
breaks the backward compatibility, we should make setAttributes()
accept decimal values as before.

Bug: 34269464
Test: flashed modified build on angler and tested with an app
Change-Id: I9a77ce341c8c8c3ea74c8592b5a821243eb0257d
2017-01-23 10:59:37 +09:00
NIEJuhu
dbe99b56ec ExifInterface: fix NegativeArraySizeException
The IFD entry has a 4-byte field COUNT. It is read as int type
and is used as array size by ExifInterface. If a crafted JPEG
file contains a negative value, a NegativeArraySizeException
occurs.

Test: passed ExifInterface CTS
Change-Id: Ief29936400f04636928df09e7f357cbf25345383
Signed-off-by: NIEJuhu <niejuhu@xiaomi.com>
2016-12-05 09:18:58 +09:00
Hyundo Moon
89779299f1 Fix wrong JavaDoc parameter names of ExifInterface.getJpegAttributes()
Test: By comparing the parameter names manually.
Change-Id: I3f67e43174754a73d498be6bf2882481cd80a648
2016-11-17 11:44:12 +09:00
Sungsoo
4d3a4132c2 resolve merge conflicts of 3fc6b8f to master
Change-Id: I004b34699fd997805d6c37753c48fe1f1d226095
2016-10-14 08:17:19 +09:00
Sungsoo
3fc6b8fd0f ExifInterface: Provide backward compatibility am: 2dbe166801 am: bc813cd510 am: 36f64a2f0c
am: b68d0855c4

Change-Id: I40df333d3b19911be333e5c466dfe01a3db4bd70
2016-10-13 22:21:47 +00:00
Sungsoo
2dbe166801 ExifInterface: Provide backward compatibility
ExifInterface.saveAttribute() didn't throw UnsupportedOperationException
before. Use IOException instead of UnsupportedOperationException for
backward compatibility.

Bug: 30936376, Bug: 32068647, Bug: 31319086
Change-Id: Ifb478db3af820eb846c5373d3a284367da3495a0
2016-10-13 13:06:24 +09:00
Sungsoo
e1b15e2117 ExifInterface: Update javadoc for saveAttributes am: abf5b4cbf3 am: d0a8a69034 am: 6e8eba7238
am: 855b9126e1

Change-Id: I4ce94f6368f41dcbf760f164b13c9d6d8055a42b
2016-09-28 00:27:20 +00:00
Sungsoo
6e8eba7238 ExifInterface: Update javadoc for saveAttributes am: abf5b4cbf3
am: d0a8a69034

Change-Id: I1d3369e609d668dc402d4b30eb0c4247980e6e47
2016-09-28 00:18:44 +00:00
Sungsoo
d0a8a69034 ExifInterface: Update javadoc for saveAttributes
am: abf5b4cbf3

Change-Id: Icdd289f513f2a576b50d0f3ddf278a1c1710d8b5
2016-09-28 00:08:52 +00:00
Sungsoo
abf5b4cbf3 ExifInterface: Update javadoc for saveAttributes
Bug: 31319086
Test: Checked the created javadoc with "make docs"
Change-Id: I97c77ba4f00a95bc5eedf1dcee942aebd2d89ccb
2016-09-27 02:04:35 +00:00
Sungsoo
4c3668d7aa DO NOT MERGE) ExifInterface: Make saveAttributes throw an exception before change
am: 56ea7b4901

Change-Id: If8497c9ad514037ce4c1f72dee6f77426d3ecd50
2016-09-09 22:46:55 +00:00
Sungsoo
56ea7b4901 DO NOT MERGE) ExifInterface: Make saveAttributes throw an exception before change
ExifInterface object can be created with a unsupported file format.
If saveAttribute is called with an unsupported file format, ExifInterface
makes the file corrupted. This CL prevents those cases by throwing
an exception before making any change on the file.

Bug: 30936376
Change-Id: I115a42601c774062485974042464abb0d65c35e9
(cherry picked from commit a8f9a075b1)
2016-09-08 08:01:13 +00:00
Colin Cross
6520711837 resolve merge conflicts of 77a7787 to master
Change-Id: I17f14a88b5b654a8860a09f610e797af15cedecc
2016-08-25 15:01:52 -07:00
Sungsoo
77a7787cab ExifInterface: Make saveAttributes throw an exception before change am: a8f9a075b1
am: 6dfc7abaf9

Change-Id: Iecc3f1dcffd540f005312e8a301335ea02cd89b9
2016-08-24 02:31:14 +00:00
Sungsoo
a8f9a075b1 ExifInterface: Make saveAttributes throw an exception before change
ExifInterface object can be created with a unsupported file format.
If saveAttribute is called with an unsupported file format, ExifInterface
makes the file corrupted. This CL prevents those cases by throwing
an exception before making any change on the file.

Bug: 30936376
Change-Id: I115a42601c774062485974042464abb0d65c35e9
2016-08-23 15:22:45 +09:00
Jin Seok Park
9dcaad655e Merge "ExifInterface: Refactor custom input stream class" 2016-08-19 08:39:41 +00:00
Jin Park
0c1640aeb4 ExifInterface: Refactor custom input stream class
ExifInterface uses a class named ByteOrderAwarenessDataInputStream
to handle LITTLE_ENDIAN byte-ordered data. This class can only be
initialized with a byte array, which is inefficient for large RAW
files. This CL adds support for initializing with an input stream.

Bug: 30749097
Change-Id: I4e95fb2157115c571ed24ec3746a3c6db752bbdc
2016-08-19 15:47:28 +09:00
Jin Park
cabb85ca4b ExifInterface: Update Pixel X/Y Dimension tag values
Current code checks Pixel X/Y Dimension tags when updating primary
image size values. This creates a problem when the image data are not
placed properly (IFD_TYPE_PRIMARY may need to be swapped with
IFD_TYPE_PREVIEW). This CL moves the updating code to after the
images have been properly placed.

Bug: 29409358
Change-Id: Ia70b5b292812c1e7812e9fc8ca2434998cf1b7f9
2016-08-18 11:52:08 +09:00
Jin Seok Park
9a03dd10c1 Merge "ExifInterface: Refactor IFD type variables" 2016-08-12 01:44:27 +00:00
Jin Park
d0e63a841a ExifInterface: Refactor IFD type variables
ExifInterface uses an ambiguous term called "hint" to indicate the
type of IFD that needs to be parsed. This CL substitutes the use of
such term with IfdType class.

Bug: 30749097
Change-Id: Id97d09882f37818978b773d55846707915efeb49
2016-08-11 10:37:35 +09:00
Jin Seok Park
c900c660bb Merge "ExifInterface: Remove JNI code" 2016-08-11 00:20:11 +00:00
Jin Park
0dd9e9cac8 ExifInterface: Remove JNI code
This CL finalizes porting piex into ExifInterface by removing JNI
methods and class as well as methods handling data received from
JNI method calls.

Bug: 29409358
Change-Id: I8f6c761e50cb29476dc0784f58908ec35e3c70e9
2016-08-10 11:49:20 +09:00
Jin Park
2574920992 ExifInterface: Add support for DNG thumbnail cases
DNG files have a unique way of identifying their image compression
type. This CL addresses this issue by adding support for cases
mentioned in the DNG Specifications.

Bug: 30727870
Change-Id: I416b9fb49872e9c878193f346dcaad5f45b0b995
2016-08-10 11:44:00 +09:00
Jin Seok Park
3d6fcede38 Merge "ExifInterface: Remove AssetInputStream dependency" 2016-08-10 02:35:53 +00:00
Jin Park
baad7d84f4 ExifInterface: Remove AssetInputStream dependency
ExifInterface calls native method to retrieve thumbnail data from an
AssetInputStream data. This CL removes that dependecy.

Bug: 29409358
Change-Id: I890b0e813733a5dcaa5480ee48e68c63fc079114
2016-08-10 10:04:07 +09:00
Jin Park
e6e4e8d7a5 ExifInterface: Fix function for image size update
Existing code assumes that the primary image data is correctly placed.
Since this may be a mistaken assumption, this CL checks the
NewSubfilType value and updates the image size values only if the
tag value equals the original resolution image.

Bug: 29409358
Change-Id: I51cffba870ee29d76118b4c8b72290d1010c6462
2016-08-09 13:18:22 +09:00
Jin Park
043785660c ExifInterface: Process uncompressed thumbnail
An uncompressed thumbnail may use 24-bit RGB format to store image
data. This CL handles uncompressed thumbnail images and creates a
bitmap object by using the given byte data.

Bug: 28156704
Change-Id: Ie650de4398004dfa74519817e417c7002d4fbdbb
2016-08-04 15:11:49 +09:00
Jin Park
b3108a0757 ExifInterface: Add support for multiple RAW test files
ARW, CR2, NEF, NRW, SRW have slight modifications to the data
structures described in TIFF Specifications. This CL handles these
modifications.

Bug: 29409358
Change-Id: I10c6b17a25d237b71d311705dfd80f7be783cd1d
2016-08-01 23:13:43 +09:00
Jin Park
9ff5cefd4e ExifInterface: Add PEF, RW2 files parse support
PEF, RW2 files have unique ways of storing their data. This CL adds code
that checks whether a file is one of these formats and parses the data
according to specifications.

Bug: 29409358
Change-Id: I6c368b4865414062f9f535bf180d7d7bf6984a7d
2016-07-26 18:27:22 +09:00
Jin Park
1c1b2b18d3 ExifInterface: Add ORF file parse support
A ORF file has a unique way of storing its data. This CL adds code
that checks whether a file is a ORF file format and parses the data
according to specifications.

Bug: 29409358
Change-Id: I498408a9e02dfe567c2d427b037c30b06af74d7e
2016-07-21 13:49:01 +09:00
Jin Park
68bda838d0 ExifInterface: Remove unnecessary logging of exceptions
ExifInterface currently logs exceptions when it encounters invalid
markers and when the file format is unsupported by Piex Library.
This CL suppresses such logs with the DEBUG marker.

Bug: 30252745
Change-Id: Ia69183eaa5bf7ac2ff1dc95c0919b23b4a9f8c4e
2016-07-21 10:27:57 +09:00
Jin Park
ffe4efc319 ExifInterface: Add RAF file parse support
A RAF format file has a unique way of storing its data. This CL adds
code that checks whether a file is a RAF file format and parses the
data according to specifications.

Bug: 29409358
Change-Id: If37d4ba8de47cdbacd524a07148ba6c14f873259
2016-07-13 07:10:16 +00:00
Jin Park
559c028fc8 ExifInterface: Extract primary image length/width values
The primary image may not contain the tags for ImageLength and
ImageWidth values if it uses the JFIF specification. This CL searches
the data to retrieve those necessary values.

Bug: 29409358
Change-Id: I850768af38b7b723e93833a70a2238f3fe1cc29b
2016-07-13 14:29:58 +09:00
Jin Park
1674546669 ExifInterface: Add support for preview images
A RAW format file may contain a preview image, in addition to a
primary image and a thumbnail image. This CL detects and parses the
preview image metadata.

Bug: 29409358
Change-Id: Ide176ea0d93228b45c50a97f82273132de25e27a
2016-07-06 14:15:15 +09:00
Jin Park
e70aab7f8a ExifInterface: Update image length/width values
A RAW file may store extra pixels around the edges of the image,
resulting in width and length tags that are larger than they actually
are. This CL addresses this issue by finding the actual values and
updating accordingly.

Bug: 29409358
Change-Id: I804bdbd7883ea860fe3425e6ce9c71334d1341a0
2016-07-04 15:18:57 +09:00