OSDN Git Service

Fix offset and ASCII type handling in exif.
[android-x86/packages-apps-Gallery2.git] / gallerycommon / src / com / android / gallery3d / exif / ExifTag.java
index 24e7f53..b8b3872 100644 (file)
@@ -330,8 +330,13 @@ public class ExifTag {
         }
 
         byte[] buf = value.getBytes(US_ASCII);
-        byte[] finalBuf = (buf[buf.length - 1] == 0 || mDataType == TYPE_UNDEFINED) ? buf : Arrays
+        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 };
+        }
         int count = finalBuf.length;
         if (checkBadComponentCount(count)) {
             return false;
@@ -870,6 +875,10 @@ public class ExifTag {
         mHasDefinedDefaultComponentCount = d;
     }
 
+    protected boolean hasDefinedCount() {
+        return mHasDefinedDefaultComponentCount;
+    }
+
     private boolean checkBadComponentCount(int count) {
         if (mHasDefinedDefaultComponentCount && (mComponentCountActual != count)) {
             return true;