summaryrefslogtreecommitdiffstats
path: root/gallerycommon/src/com/android/gallery3d
diff options
context:
space:
mode:
authorFlamefire <alex@grundis.de>2014-08-24 16:26:09 +0200
committerSteve Kondik <steve@cyngn.com>2015-03-28 14:58:54 -0700
commitbc5f6cc1c376878786dd70042a9e0f8c18c3723a (patch)
tree254d0aeaa9666be06777aad6458dc9956b00003e /gallerycommon/src/com/android/gallery3d
parent8d797f65f9a371c534866d27df287728200dde93 (diff)
downloadandroid_packages_apps_Gallery2-bc5f6cc1c376878786dd70042a9e0f8c18c3723a.tar.gz
android_packages_apps_Gallery2-bc5f6cc1c376878786dd70042a9e0f8c18c3723a.tar.bz2
android_packages_apps_Gallery2-bc5f6cc1c376878786dd70042a9e0f8c18c3723a.zip
Fix crash of gallery on showing details
The exif parser adds a terminating zero for string values. This increases the byte count for that entry beyond the set byte count. Causing a null value in e.g. the "Model" field for images taken with e.g. a Samsung Wave 2. Change-Id: Ifb6ee4d5b4b71e84cb2a5df459d3716543e25efe
Diffstat (limited to 'gallerycommon/src/com/android/gallery3d')
-rw-r--r--gallerycommon/src/com/android/gallery3d/exif/ExifTag.java33
1 files changed, 23 insertions, 10 deletions
diff --git a/gallerycommon/src/com/android/gallery3d/exif/ExifTag.java b/gallerycommon/src/com/android/gallery3d/exif/ExifTag.java
index b8b387201..c30a97143 100644
--- a/gallerycommon/src/com/android/gallery3d/exif/ExifTag.java
+++ b/gallerycommon/src/com/android/gallery3d/exif/ExifTag.java
@@ -314,13 +314,17 @@ public class ExifTag {
* Sets a string value into this tag. This method should be used for tags of
* type {@link #TYPE_ASCII}. The string is converted to an ASCII string.
* Characters that cannot be converted are replaced with '?'. The length of
- * the string must be equal to either (component count -1) or (component
- * count). The final byte will be set to the string null terminator '\0',
- * overwriting the last character in the string if the value.length is equal
- * to the component count. This method will fail if:
+ * the string must be equal to either
+ * <ul>
+ * <li>component count - 1 when the terminating '\0' is not present</li>
+ * <li>component count when the terminating '\0' is present</li>
+ * <li>to comply with some non-conformant implementations, the terminating
+ * '\0' will be appended if it's not present and component count equals
+ * the string length; the component count will be updated in that case</li>
+ * This method will fail if:
* <ul>
* <li>The data type is not {@link #TYPE_ASCII} or {@link #TYPE_UNDEFINED}.</li>
- * <li>The length of the string is not equal to (component count -1) or
+ * <li>The length of the string is not equal to (component count - 1) or
* (component count) in the definition for this tag.</li>
* </ul>
*/
@@ -331,11 +335,20 @@ public class ExifTag {
byte[] buf = value.getBytes(US_ASCII);
byte[] finalBuf = buf;
- if (buf.length > 0) {
- finalBuf = (buf[buf.length - 1] == 0 || mDataType == TYPE_UNDEFINED) ? buf : Arrays
- .copyOf(buf, buf.length + 1);
- } else if (mDataType == TYPE_ASCII && mComponentCountActual == 1) {
- finalBuf = new byte[] { 0 };
+ if (mDataType == TYPE_ASCII) {
+ if (buf.length > 0) {
+ if (buf[buf.length - 1] != 0) {
+ finalBuf = Arrays.copyOf(buf, buf.length + 1);
+ // Apply the workaround for non conformant implementations
+ // (e.g. Samsung Wave 2): Accept a string with missing
+ // termination character
+ if (mComponentCountActual == buf.length) {
+ mComponentCountActual++;
+ }
+ }
+ } else if (mComponentCountActual == 1) {
+ finalBuf = new byte[] { 0 };
+ }
}
int count = finalBuf.length;
if (checkBadComponentCount(count)) {