Constant pool overflow (PATCH)
strk <[email protected]> Wed, 17 Sep 2003 19:31:01 +0200
| Newsgroups | gmane.comp.web.ming.general |
|---|---|
| Message-ID | <[email protected]> |
This patch should fix the problem
(if I didn't allow too many bytes in the introduced limits)
--strk;
-----------------8<------------------------ cut here ------------
diff -rU2 ming.000/src/actioncompiler/compile.c ming/src/actioncompiler/compile.c
--- ming.000/src/actioncompiler/compile.c Wed Sep 17 15:57:10 2003
+++ ming/src/actioncompiler/compile.c Wed Sep 17 19:17:41 2003
@@ -29,5 +29,5 @@
#include "compile.h"
-static int nConstants = {0}, maxConstants = {0};
+static int nConstants = {0}, maxConstants = {0}, sizeConstants = {0};
static char **constants;
@@ -121,7 +121,19 @@
}
+ /* Don't let constant pool biggern then allowed */
+ if ( sizeConstants+strlen(s)+1 > MAXCONSTANTPOOLSIZE ) return -1;
+
if(nConstants == maxConstants)
- constants = (char **) realloc(constants, (maxConstants += 64) * sizeof(char *));
+ {
+ /* Do not allow for more then MAXCONSTANTPOOLITEMS constants */
+ if ( nConstants+1 == MAXCONSTANTPOOLITEMS ) return -1;
+ if ( maxConstants+64 > MAXCONSTANTPOOLITEMS )
+ maxConstants += 64;
+ else maxConstants = MAXCONSTANTPOOLITEMS;
+ constants = (char **) realloc(constants, maxConstants * sizeof(char *));
+ }
+
constants[nConstants] = strdup(s);
+ sizeConstants += (strlen(s)+1);
return nConstants++;
}
diff -rU2 ming.000/src/actioncompiler/compile.h ming/src/actioncompiler/compile.h
--- ming.000/src/actioncompiler/compile.h Wed Sep 17 15:57:10 2003
+++ ming/src/actioncompiler/compile.h Wed Sep 17 19:16:43 2003
@@ -118,4 +118,7 @@
int addConstant(const char *s);
int bufferWriteConstants(Buffer out);
+#define MAXCONSTANTPOOLITEMS 256
+/* 2bytes are for the lenght field */
+#define MAXCONSTANTPOOLSIZE 65533
/* write data to buffer */
-----------------8<------------------------ cut here ------------
strk wrote:
> Hello,
> I'm having a constant pool overflow problems with Ming (latest CVS).
> The problem seems to be exactly described here:
>
> from: http://www.nowrap.de/flasm.html
> --8<---------------------------------
> While it's good practice to keep scripts smaller than 64k (compiled) per
> frame, it's possible to get larger. But the sole action record - constants,
> push, function and other is limited to 64k because of 2 bytes length field
> size.
>
> Since flash will create (in 99% of cases) the constant pool for all
> variables and methods, overflow is possible.
>
> It's a pity flash itself doesn't tell you the script is too big.
> Instead flash compiler writes overflowed value to the length field without
> errors or warnings. If you try to execute the swf, flash player crashes,
> or actions are omitted. flasm will stop disassembling with an error message
> if such overflowed constant pool definition is
> encountered in swf.
> --8<---------------------------------
>
> I know this is the problem because flasm (as in the last statement)
> stops and dumps the error: Too many constants. The output of course
> is corrupted (action scrambled don't know how - missing variables),
> while the same actionscript file compiled with MX gives successful
> result.
>
> This document refers to the flash authoring environment prior to MX.
> MX corrects this.
>
> What about Ming ?
>
> --strk;
> _______________________________________________
> ming-fun mailing list
> [email protected]
> http://www.opaque.net/mailman/listinfo/ming-fun