summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChong Zhang <chz@google.com>2018-11-30 14:25:08 -0800
committerHung-ying Tyan <tyanh@google.com>2019-04-25 11:41:41 +0800
commit44d06fdef904bf19c7326fe43308b763740a6fb8 (patch)
tree0b477f0b7323a511e4fcc9269659f2647640121d
parentd63b2d51026237a1ad180146a5bea7bb17e4e2ec (diff)
downloadbase-44d06fdef904bf19c7326fe43308b763740a6fb8.tar.gz
Fix ExifInterface for .heic when meta is at the end
available() bytes is counted after the last read position, after the seek to new position, size should be compared with the avaliable directly (without adding position). bug: 120086693 test: Open .heic files in Downloads/Photos that's either very small (b/117625929, b/111897855), or with the meta at the very end (b/120086693). There shouldn't be error in ExifInterface. Change-Id: I37ac57823b26f03bb0ba555ee6213cf999942d21
-rw-r--r--media/java/android/media/ExifInterface.java14
1 files changed, 14 insertions, 0 deletions
diff --git a/media/java/android/media/ExifInterface.java b/media/java/android/media/ExifInterface.java
index aa457092ca3f..505e72a1cfae 100644
--- a/media/java/android/media/ExifInterface.java
+++ b/media/java/android/media/ExifInterface.java
@@ -2542,10 +2542,24 @@ public class ExifInterface {
}
try {
if (mPosition != position) {
+ // We don't allow seek to positions after the available bytes,
+ // the input stream won't be able to seek back then.
+ // However, if we hit an exception before (mPosition set to -1),
+ // let it try the seek in hope it might recover.
+ if (mPosition >= 0 && position >= mPosition + in.available()) {
+ return -1;
+ }
in.seek(position);
mPosition = position;
}
+ // If the read will cause us to go over the available bytes,
+ // reduce the size so that we stay in the available range.
+ // Otherwise the input stream may not be able to seek back.
+ if (size > in.available()) {
+ size = in.available();
+ }
+
int bytesRead = in.read(buffer, offset, size);
if (bytesRead >= 0) {
mPosition += bytesRead;