From 09b7ee71c26133cdfdb23008254fcabea88cbc2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sat, 27 Apr 2013 11:32:11 +0200 Subject: [PATCH] premature end of tag detection DefineMorphShape2 fix --- .../flash/EndOfStreamException.java | 29 +++++++++++++++++++ .../decompiler/flash/SWFInputStream.java | 18 ++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 trunk/src/com/jpexs/decompiler/flash/EndOfStreamException.java diff --git a/trunk/src/com/jpexs/decompiler/flash/EndOfStreamException.java b/trunk/src/com/jpexs/decompiler/flash/EndOfStreamException.java new file mode 100644 index 000000000..554cb470f --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/EndOfStreamException.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2010-2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash; + +/** + * + * @author JPEXS + */ +public class EndOfStreamException extends RuntimeException { + + public EndOfStreamException() { + super("Premature end of the stream reached"); + } + +} diff --git a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java index 4f7a455a9..32ac5fba4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -185,7 +185,11 @@ public class SWFInputStream extends InputStream { lastPercent = percent; } } - return is.read(); + int r = is.read(); + if (r == -1) { + throw new EndOfStreamException(); + } + return r; } /** @@ -1393,7 +1397,13 @@ public class SWFInputStream extends InputStream { */ public Action readAction(ReReadableInputStream rri) throws IOException { { - int actionCode = readUI8(); + int actionCode = -1; + + try{ + actionCode=readUI8(); + }catch(EndOfStreamException eos){ + return null; + } if (actionCode == 0) { return new ActionEnd(); } @@ -2576,7 +2586,9 @@ public class SWFInputStream extends InputStream { */ public MORPHGRADIENT readMORPHGRADIENT() throws IOException { MORPHGRADIENT ret = new MORPHGRADIENT(); - int numGradients = (int) readUI8(); + int numGradients = (int) readUI8(); + numGradients = numGradients % 8; //there should be 1 to 8 but sometimes there is more. This modulo seems to be OK. + ret.gradientRecords = new MORPHGRADRECORD[numGradients]; for (int i = 0; i < numGradients; i++) { ret.gradientRecords[i] = readMORPHGRADRECORD();