From 166e2f7822460b575c8fe0eebb40aabb2b8dc08d Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Mon, 23 Mar 2015 16:33:02 +0100 Subject: [PATCH] ignore invalid tags in test (do not use lazy loading in tests) --- .../src/com/jpexs/decompiler/flash/SWF.java | 26 ++++++++++++++----- .../decompiler/flash/SWFInputStream.java | 21 +++++++++------ .../com/jpexs/decompiler/flash/SWFSearch.java | 2 +- .../flash/tags/DefineSpriteTag.java | 2 +- .../jpexs/decompiler/flash/RecompileTest.java | 2 +- 5 files changed, 36 insertions(+), 17 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index 64df99a0d..24d8c7451 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -745,7 +745,20 @@ public final class SWF implements SWFContainerItem, Timelined { * @throws java.lang.InterruptedException */ public SWF(InputStream is, boolean parallelRead) throws IOException, InterruptedException { - this(is, null, null, null, parallelRead, false); + this(is, null, null, null, parallelRead, false, true); + } + + /** + * Construct SWF from stream + * + * @param is Stream to read SWF from + * @param parallelRead Use parallel threads? + * @param lazy + * @throws IOException + * @throws java.lang.InterruptedException + */ + public SWF(InputStream is, boolean parallelRead, boolean lazy) throws IOException, InterruptedException { + this(is, null, null, null, parallelRead, false, lazy); } /** @@ -759,7 +772,7 @@ public final class SWF implements SWFContainerItem, Timelined { * @throws java.lang.InterruptedException */ public SWF(InputStream is, String file, String fileTitle, boolean parallelRead) throws IOException, InterruptedException { - this(is, file, fileTitle, null, parallelRead, false); + this(is, file, fileTitle, null, parallelRead, false, true); } /** @@ -772,7 +785,7 @@ public final class SWF implements SWFContainerItem, Timelined { * @throws java.lang.InterruptedException */ public SWF(InputStream is, ProgressListener listener, boolean parallelRead) throws IOException, InterruptedException { - this(is, null, null, listener, parallelRead, false); + this(is, null, null, listener, parallelRead, false, true); } /** @@ -787,7 +800,7 @@ public final class SWF implements SWFContainerItem, Timelined { * @throws java.lang.InterruptedException */ public SWF(InputStream is, String file, String fileTitle, ProgressListener listener, boolean parallelRead) throws IOException, InterruptedException { - this(is, file, fileTitle, listener, parallelRead, false); + this(is, file, fileTitle, listener, parallelRead, false, true); } /** @@ -809,10 +822,11 @@ public final class SWF implements SWFContainerItem, Timelined { * @param listener * @param parallelRead Use parallel threads? * @param checkOnly Check only file validity + * @param lazy * @throws IOException * @throws java.lang.InterruptedException */ - public SWF(InputStream is, String file, String fileTitle, ProgressListener listener, boolean parallelRead, boolean checkOnly) throws IOException, InterruptedException { + public SWF(InputStream is, String file, String fileTitle, ProgressListener listener, boolean parallelRead, boolean checkOnly, boolean lazy) throws IOException, InterruptedException { this.file = file; this.fileTitle = fileTitle; ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -839,7 +853,7 @@ public final class SWF implements SWFContainerItem, Timelined { sis.readUI8("tmpFirstByetOfFrameRate"); // tmpFirstByetOfFrameRate frameRate = sis.readUI8("frameRate"); frameCount = sis.readUI16("frameCount"); - List tags = sis.readTagList(this, 0, parallelRead, true, !checkOnly); + List tags = sis.readTagList(this, 0, parallelRead, true, !checkOnly, lazy); if (tags.size() > 0 && tags.get(tags.size() - 1).getId() == EndTag.ID) { tags.remove(tags.size() - 1); } else { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java index a31e90123..db7ef3dfe 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -1017,19 +1017,22 @@ public class SWFInputStream implements AutoCloseable { private final boolean skipUnusualTags; - public TagResolutionTask(TagStub tag, DumpInfo dumpInfo, int level, boolean parallel, boolean skipUnusualTags) { + private final boolean lazy; + + public TagResolutionTask(TagStub tag, DumpInfo dumpInfo, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) { this.tag = tag; this.dumpInfo = dumpInfo; this.level = level; this.parallel = parallel; this.skipUnusualTags = skipUnusualTags; + this.lazy = lazy; } @Override public Tag call() throws Exception { DumpInfo di = dumpInfo; try { - Tag t = resolveTag(tag, level, parallel, skipUnusualTags, true); + Tag t = resolveTag(tag, level, parallel, skipUnusualTags, lazy); if (dumpInfo != null && t != null) { dumpInfo.name = t.getName(); } @@ -1051,11 +1054,12 @@ public class SWFInputStream implements AutoCloseable { * @param parallel * @param skipUnusualTags * @param parseTags + * @param lazy * @return List of tags * @throws IOException * @throws java.lang.InterruptedException */ - public List readTagList(Timelined timelined, int level, boolean parallel, boolean skipUnusualTags, boolean parseTags) throws IOException, InterruptedException { + public List readTagList(Timelined timelined, int level, boolean parallel, boolean skipUnusualTags, boolean parseTags, boolean lazy) throws IOException, InterruptedException { boolean parallel1 = level == 0 && parallel; ExecutorService executor = null; List> futureResults = new ArrayList<>(); @@ -1070,7 +1074,7 @@ public class SWFInputStream implements AutoCloseable { long pos = getPos(); newDumpLevel(null, "TAG"); try { - tag = readTag(timelined, level, pos, parseTags && !parallel1, parallel1, skipUnusualTags); + tag = readTag(timelined, level, pos, parseTags && !parallel1, parallel1, skipUnusualTags, lazy); } catch (EOFException | EndOfStreamException ex) { tag = null; } @@ -1098,7 +1102,7 @@ public class SWFInputStream implements AutoCloseable { switch (tag.getId()) { case FileAttributesTag.ID: // FileAttributes if (tag instanceof TagStub) { - tag = resolveTag((TagStub) tag, level, parallel1, skipUnusualTags, true); + tag = resolveTag((TagStub) tag, level, parallel1, skipUnusualTags, lazy); } FileAttributesTag fileAttributes = (FileAttributesTag) tag; if (fileAttributes.actionScript3) { @@ -1140,7 +1144,7 @@ public class SWFInputStream implements AutoCloseable { } } if (parseTags && doParse && parallel1 && tag instanceof TagStub) { - Future future = executor.submit(new TagResolutionTask((TagStub) tag, di, level, parallel1, skipUnusualTags)); + Future future = executor.submit(new TagResolutionTask((TagStub) tag, di, level, parallel1, skipUnusualTags, lazy)); futureResults.add(future); } else { Future future = new ImmediateFuture<>(tag); @@ -1472,11 +1476,12 @@ public class SWFInputStream implements AutoCloseable { * @param resolve * @param parallel * @param skipUnusualTags + * @param lazy * @return Tag or null when End tag * @throws IOException * @throws java.lang.InterruptedException */ - public Tag readTag(Timelined timelined, int level, long pos, boolean resolve, boolean parallel, boolean skipUnusualTags) throws IOException, InterruptedException { + public Tag readTag(Timelined timelined, int level, long pos, boolean resolve, boolean parallel, boolean skipUnusualTags, boolean lazy) throws IOException, InterruptedException { int tagIDTagLength = readUI16("tagIDTagLength"); int tagID = (tagIDTagLength) >> 6; @@ -1509,7 +1514,7 @@ public class SWFInputStream implements AutoCloseable { if (resolve) { DumpInfo di = dumpInfo; try { - ret = resolveTag(tagStub, level, parallel, skipUnusualTags, true); + ret = resolveTag(tagStub, level, parallel, skipUnusualTags, lazy); } catch (Exception ex) { tagDataStream.endDumpLevelUntil(di); logger.log(Level.SEVERE, "Problem in " + timelined.toString(), ex); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFSearch.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFSearch.java index 83a67585c..e9af2ba4f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFSearch.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFSearch.java @@ -90,7 +90,7 @@ public class SWFSearch { MemoryInputStream mis = (MemoryInputStream) ret.get(addr); mis.reset(); PosMarkedInputStream pmi = new PosMarkedInputStream(mis); - SWF swf = noCheck ? new SWF(pmi) : new SWF(pmi, null, null, null, false, true); + SWF swf = noCheck ? new SWF(pmi) : new SWF(pmi, null, null, null, false, true, true); boolean valid = swf.fileSize > 0 && swf.version > 0 && (!swf.tags.isEmpty() || noCheck) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java index 1e1495c97..c67c208b9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java @@ -225,7 +225,7 @@ public class DefineSpriteTag extends CharacterTag implements DrawableTag, Timeli public final void readData(SWFInputStream sis, ByteArrayRange data, int level, boolean parallel, boolean skipUnusualTags, boolean lazy) throws IOException, InterruptedException { spriteId = sis.readUI16("spriteId"); frameCount = sis.readUI16("frameCount"); - List subTags = sis.readTagList(this, level + 1, parallel, skipUnusualTags, true); + List subTags = sis.readTagList(this, level + 1, parallel, skipUnusualTags, true, lazy); if (subTags.size() > 0 && subTags.get(subTags.size() - 1).getId() == EndTag.ID) { hasEndTag = true; subTags.remove(subTags.size() - 1); diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java index df3d17baf..06b77b879 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java @@ -85,7 +85,7 @@ public class RecompileTest extends FileTestBase { public void testTagEditing(String fileName) throws IOException, InterruptedException { try { Configuration.debugCopy.set(false); - SWF swf = new SWF(new BufferedInputStream(new FileInputStream(TESTDATADIR + File.separator + fileName)), false); + SWF swf = new SWF(new BufferedInputStream(new FileInputStream(TESTDATADIR + File.separator + fileName)), false, false); for (Tag tag : swf.tags) { if (!(tag instanceof TagStub)) { Tag tag2 = tag.cloneTag();