summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2018-10-23 17:36:33 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2018-10-23 17:36:33 +0000
commit31bbb473ce5c0a7bf219f13f86f9f5d701369ee9 (patch)
treef0e307635a2d657b8f57e6ca98279c36a5fd550b
parent09159319395233c38b1a4b5b8810d60f43187b4b (diff)
parentf2b041dce0b855ecc7eec6514b5b0c3785378855 (diff)
Merge "Fix data source for HEIF exif extractor"
-rw-r--r--media/java/android/media/ExifInterface.java11
1 files changed, 10 insertions, 1 deletions
diff --git a/media/java/android/media/ExifInterface.java b/media/java/android/media/ExifInterface.java
index a959759b78de..2395b24f7136 100644
--- a/media/java/android/media/ExifInterface.java
+++ b/media/java/android/media/ExifInterface.java
@@ -2545,7 +2545,9 @@ public class ExifInterface {
if (size == 0) {
return 0;
}
- if (position < 0) {
+ // We don't allow read positions after the available bytes,
+ // the input stream won't be able to seek back then.
+ if (position < 0 || position >= in.available()) {
return -1;
}
try {
@@ -2554,6 +2556,13 @@ public class ExifInterface {
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 (mPosition + size > in.available()) {
+ size = in.available() - (int)mPosition;
+ }
+
int bytesRead = in.read(buffer, offset, size);
if (bytesRead >= 0) {
mPosition += bytesRead;