From bdcdb15ad345633bbab6505207008f018059f107 Mon Sep 17 00:00:00 2001 From: Earl Ou Date: Fri, 3 Aug 2012 13:26:35 +0800 Subject: Remove TYPE_SUB_IFD for next() in IfdParser We should not read the offset because there are too many exception. Users should check the id of the tag and decide how to read the block by themselves. Change-Id: Ie3f162c5c6dc25f15107e193adc080c7b51112b5 --- .../com/android/gallery3d/exif/ExifParserTest.java | 60 +++++++++++----------- 1 file changed, 29 insertions(+), 31 deletions(-) (limited to 'tests') diff --git a/tests/src/com/android/gallery3d/exif/ExifParserTest.java b/tests/src/com/android/gallery3d/exif/ExifParserTest.java index 3c9d276e5..a2c53831f 100644 --- a/tests/src/com/android/gallery3d/exif/ExifParserTest.java +++ b/tests/src/com/android/gallery3d/exif/ExifParserTest.java @@ -120,8 +120,10 @@ public class ExifParserTest extends ActivityTestCase { switch (type) { case IfdParser.TYPE_NEW_TAG: ExifTag tag = ifdParser.readTag(); - if (tag.getOffset() > 0) { - ifdParser.waitValueOfTag(tag); + if (tag.getDataSize() > 4 || tag.getTagId() == ExifTag.TIFF_TAG.TAG_EXIF_IFD) { + long offset = ifdParser.readUnsignedInt(); + assertTrue(offset <= Integer.MAX_VALUE); + ifdParser.waitValueOfTag(tag, offset); } else { checkTag(tag, ifdParser, IFD0_VALUE); tagNumber++; @@ -130,14 +132,14 @@ public class ExifParserTest extends ActivityTestCase { case IfdParser.TYPE_NEXT_IFD: parseIfd1(ifdParser.parseIfdBlock()); break; - case IfdParser.TYPE_SUB_IFD: - assertEquals(ExifTag.TIFF_TAG.TAG_EXIF_IFD, - ifdParser.getCorrespodingExifTag().getTagId()); - parseExifIfd(ifdParser.parseIfdBlock()); - break; case IfdParser.TYPE_VALUE_OF_PREV_TAG: - checkTag(ifdParser.getCorrespodingExifTag(), ifdParser, IFD0_VALUE); - tagNumber++; + tag = ifdParser.getCorrespodingExifTag(); + if(tag.getTagId() == ExifTag.TIFF_TAG.TAG_EXIF_IFD) { + parseExifIfd(ifdParser.parseIfdBlock()); + } else { + checkTag(ifdParser.getCorrespodingExifTag(), ifdParser, IFD0_VALUE); + tagNumber++; + } break; } type = ifdParser.next(); @@ -153,8 +155,10 @@ public class ExifParserTest extends ActivityTestCase { switch (type) { case IfdParser.TYPE_NEW_TAG: ExifTag tag = ifdParser.readTag(); - if (tag.getOffset() > 0) { - ifdParser.waitValueOfTag(tag); + if (tag.getDataSize() > 4) { + long offset = ifdParser.readUnsignedInt(); + assertTrue(offset <= Integer.MAX_VALUE); + ifdParser.waitValueOfTag(tag, offset); } else { checkTag(tag, ifdParser, IFD1_VALUE); tagNumber++; @@ -163,9 +167,6 @@ public class ExifParserTest extends ActivityTestCase { case IfdParser.TYPE_NEXT_IFD: fail("Find a ifd after ifd1"); break; - case IfdParser.TYPE_SUB_IFD: - fail("Find a sub ifd in ifd1"); - break; case IfdParser.TYPE_VALUE_OF_PREV_TAG: checkTag(ifdParser.getCorrespodingExifTag(), ifdParser, IFD1_VALUE); tagNumber++; @@ -184,8 +185,10 @@ public class ExifParserTest extends ActivityTestCase { switch (type) { case IfdParser.TYPE_NEW_TAG: ExifTag tag = ifdParser.readTag(); - if (tag.getOffset() > 0) { - ifdParser.waitValueOfTag(tag); + if (tag.getDataSize() > 4) { + long offset = ifdParser.readUnsignedInt(); + assertTrue(offset <= Integer.MAX_VALUE); + ifdParser.waitValueOfTag(tag, offset); } else { checkTag(tag, ifdParser, EXIF_IFD_VALUE); tagNumber++; @@ -194,9 +197,6 @@ public class ExifParserTest extends ActivityTestCase { case IfdParser.TYPE_NEXT_IFD: fail("Find a ifd after exif ifd"); break; - case IfdParser.TYPE_SUB_IFD: - fail("Find a sub ifd in exif ifd"); - break; case IfdParser.TYPE_VALUE_OF_PREV_TAG: checkTag(ifdParser.getCorrespodingExifTag(), ifdParser, EXIF_IFD_VALUE); tagNumber++; @@ -282,10 +282,6 @@ public class ExifParserTest extends ActivityTestCase { case IfdParser.TYPE_NEXT_IFD: parseIfd1(ifdParser.parseIfdBlock()); break; - case IfdParser.TYPE_SUB_IFD: - // We won't get this since to skip everything - fail("Get sub ifd but we've skip everything"); - break; case IfdParser.TYPE_VALUE_OF_PREV_TAG: // We won't get this since to skip everything fail("Get value of previous tag but we've skip everything"); @@ -304,23 +300,25 @@ public class ExifParserTest extends ActivityTestCase { case IfdParser.TYPE_NEW_TAG: ExifTag tag = ifdParser.readTag(); // only interested in these two tags - if (tag.getOffset() > 0) { + if (tag.getDataSize() > 4 || tag.getTagId() == ExifTag.TIFF_TAG.TAG_EXIF_IFD) { if(tag.getTagId() == ExifTag.TIFF_TAG.TAG_MODEL || tag.getTagId() == ExifTag.TIFF_TAG.TAG_EXIF_IFD) { - ifdParser.waitValueOfTag(tag); + long offset = ifdParser.readUnsignedInt(); + assertTrue(offset <= Integer.MAX_VALUE); + ifdParser.waitValueOfTag(tag, offset); } } break; case IfdParser.TYPE_NEXT_IFD: parseIfd1(ifdParser.parseIfdBlock()); break; - case IfdParser.TYPE_SUB_IFD: - assertEquals(ExifTag.TIFF_TAG.TAG_EXIF_IFD, - ifdParser.getCorrespodingExifTag().getTagId()); - parseExifIfd(ifdParser.parseIfdBlock()); - break; case IfdParser.TYPE_VALUE_OF_PREV_TAG: - checkTag(ifdParser.getCorrespodingExifTag(), ifdParser, IFD0_VALUE); + tag = ifdParser.getCorrespodingExifTag(); + if(tag.getTagId() == ExifTag.TIFF_TAG.TAG_EXIF_IFD) { + parseExifIfd(ifdParser.parseIfdBlock()); + } else { + checkTag(ifdParser.getCorrespodingExifTag(), ifdParser, IFD0_VALUE); + } break; } type = ifdParser.next(); -- cgit v1.2.3