diff --git a/CHANGELOG.md b/CHANGELOG.md index 5337bd04b..064422939 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ All notable changes to this project will be documented in this file. - [#1938] "Open loaded during play" Loader injection for Multiname types - AS3 - not using visitCode when not needed => faster decompilation - Cache thread as daemon +- [#1949] Incorrect reading FIXED and FIXED8 SWF values causing wrong Filters size and OutOfMemory ## [18.3.2] - 2023-01-10 ### Removed @@ -2910,6 +2911,7 @@ All notable changes to this project will be documented in this file. [#1458]: https://www.free-decompiler.com/flash/issues/1458 [#1842]: https://www.free-decompiler.com/flash/issues/1842 [#1938]: https://www.free-decompiler.com/flash/issues/1938 +[#1949]: https://www.free-decompiler.com/flash/issues/1949 [#1935]: https://www.free-decompiler.com/flash/issues/1935 [#1931]: https://www.free-decompiler.com/flash/issues/1931 [#1934]: https://www.free-decompiler.com/flash/issues/1934 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 8d877a488..d01e97640 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -593,14 +593,19 @@ public class SWFInputStream implements AutoCloseable { */ public long readSI32(String name) throws IOException { newDumpLevel(name, "SI32"); - long uval = readEx() + (readEx() << 8) + (readEx() << 16) + (readEx() << 24); - if (uval >= 0x80000000) { - uval = -(((~uval) & 0xffffffff) + 1); - } + long uval = readSI32Internal(); endDumpLevel(uval); return uval; } + private long readSI32Internal() throws IOException { + long uval = readEx() + (readEx() << 8) + (readEx() << 16) + (readEx() << 24); + if (uval >= 0x80000000) { + uval = -(((~uval) & 0xffffffff) + 1); + } + return uval; + } + /** * Reads one SI16 (Signed 16bit integer) value from the stream * @@ -610,11 +615,16 @@ public class SWFInputStream implements AutoCloseable { */ public int readSI16(String name) throws IOException { newDumpLevel(name, "SI16"); + int uval = readSI16Internal(); + endDumpLevel(uval); + return uval; + } + + private int readSI16Internal() throws IOException { int uval = readEx() + (readEx() << 8); if (uval >= 0x8000) { uval = -(((~uval) & 0xffff) + 1); } - endDumpLevel(uval); return uval; } @@ -655,9 +665,8 @@ public class SWFInputStream implements AutoCloseable { */ public double readFIXED(String name) throws IOException { newDumpLevel(name, "FIXED"); - int afterPoint = readUI16Internal(); - int beforePoint = readUI16Internal(); - double ret = beforePoint + ((double) (afterPoint)) / 65536; + long si = readSI32Internal(); + double ret = si / (double)(1 << 16); endDumpLevel(ret); return ret; } @@ -671,9 +680,8 @@ public class SWFInputStream implements AutoCloseable { */ public float readFIXED8(String name) throws IOException { newDumpLevel(name, "FIXED8"); - int afterPoint = readEx(); - int beforePoint = readSI8Internal(); - float ret = beforePoint + ((float) afterPoint) / 256; + int si = readSI16Internal(); + float ret = si / (float)(1 << 8); endDumpLevel(ret); return ret; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFOutputStream.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFOutputStream.java index 472aae30e..caa416210 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFOutputStream.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFOutputStream.java @@ -285,10 +285,7 @@ public class SWFOutputStream extends OutputStream { */ public void writeFIXED(double value) throws IOException { long valueLong = (long) (value * (1 << 16)); - int beforePoint = (int) valueLong >> 16; - int afterPoint = (int) valueLong % (1 << 16); - writeUI16(afterPoint); - writeUI16(beforePoint); + writeSI32(valueLong); } /** @@ -299,10 +296,7 @@ public class SWFOutputStream extends OutputStream { */ public void writeFIXED8(float value) throws IOException { int valueInt = (int) (value * (1 << 8)); - int beforePoint = (int) valueInt >> 8; - int afterPoint = (int) valueInt % (1 << 8); - writeUI8(afterPoint); - writeSI8(beforePoint); + writeSI16(valueInt); } private void writeLong(long value) throws IOException {