summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEarl Ou <shunhsingou@google.com>2012-08-08 15:19:13 +0800
committerEarl Ou <shunhsingou@google.com>2012-08-08 15:19:13 +0800
commit0d64f476c62215c7738655f62b89f93ac60c7fe2 (patch)
tree7bcc32887b8e73ede7a484dd8601c9707637e457
parentab3625ea8cab1cc338578090feefeb642f109eca (diff)
downloadandroid_packages_apps_Snap-0d64f476c62215c7738655f62b89f93ac60c7fe2.tar.gz
android_packages_apps_Snap-0d64f476c62215c7738655f62b89f93ac60c7fe2.tar.bz2
android_packages_apps_Snap-0d64f476c62215c7738655f62b89f93ac60c7fe2.zip
Handle error when string length=0 in IfdParser
Change-Id: I3a51e85060f3acd5026555e5f8d21f8cb2e0641e
-rw-r--r--src/com/android/gallery3d/exif/IfdParser.java10
-rw-r--r--tests/src/com/android/gallery3d/exif/ExifParserTest.java8
2 files changed, 9 insertions, 9 deletions
diff --git a/src/com/android/gallery3d/exif/IfdParser.java b/src/com/android/gallery3d/exif/IfdParser.java
index b0b0bce10..0d1059cb0 100644
--- a/src/com/android/gallery3d/exif/IfdParser.java
+++ b/src/com/android/gallery3d/exif/IfdParser.java
@@ -125,9 +125,13 @@ public class IfdParser {
}
public String readString(int n) throws IOException {
- byte[] buf = new byte[n];
- mTiffStream.readOrThrow(buf);
- return new String(buf, 0, n - 1, "UTF8");
+ if (n > 0) {
+ byte[] buf = new byte[n];
+ mTiffStream.readOrThrow(buf);
+ return new String(buf, 0, n - 1, "UTF8");
+ } else {
+ return "";
+ }
}
public String readString(int n, Charset charset) throws IOException {
diff --git a/tests/src/com/android/gallery3d/exif/ExifParserTest.java b/tests/src/com/android/gallery3d/exif/ExifParserTest.java
index 34bbbda5f..35f4f3f1f 100644
--- a/tests/src/com/android/gallery3d/exif/ExifParserTest.java
+++ b/tests/src/com/android/gallery3d/exif/ExifParserTest.java
@@ -283,12 +283,8 @@ public class ExifParserTest extends InstrumentationTestCase {
}
break;
case ExifTag.TYPE_ASCII:
- buf = new byte[tag.getComponentCount()];
- parser.read(buf);
- int length = 0;
- while (buf[length] != 0 && length < buf.length) length++;
- // trim the string to fit the answer from xml
- sbuilder.append(new String(buf, 0, length).trim());
+ // trim the string for comparison between xml
+ sbuilder.append(parser.readString(tag.getComponentCount()).trim());
break;
case ExifTag.TYPE_INT:
for(int i = 0; i < tag.getComponentCount(); i++) {