made parser more robust against broken as3
[swftools.git] / lib / as3 / pool.c
index a74ddb2..2402328 100644 (file)
@@ -522,14 +522,17 @@ char* multiname_tostring(multiname_t*m)
     int namelen = strlen(name);
 
     if(m->type==QNAME || m->type==QNAMEA || m->type==POSTFIXTYPE) {
-        char*nsname = escape_string(m->ns->name);
+        char*nsname = m->ns?escape_string(m->ns->name):strdup("NULL");
         mname = malloc(strlen(nsname)+namelen+32);
         strcpy(mname, "<q");
         if(m->type == QNAMEA)
             strcat(mname, ",attr");
-        strcat(mname, ">[");
-        strcat(mname,access2str(m->ns->access));
-        strcat(mname, "]");
+       strcat(mname, ">");
+       if(m->ns) {
+           strcat(mname,"[");
+           strcat(mname,access2str(m->ns->access));
+           strcat(mname, "]");
+       }
         strcat(mname, nsname);
         free(nsname);
         strcat(mname, "::");
@@ -657,7 +660,7 @@ constant_t* constant_new_float(double f)
     c->type = CONSTANT_FLOAT;
     return c;
 }
-constant_t* constant_new_string(char*s)
+constant_t* constant_new_string(const char*s)
 {
     NEW(constant_t,c);
     c->s = string_new4(s);
@@ -800,6 +803,10 @@ int constant_get_index(pool_t*pool, constant_t*c)
         return pool_register_float(pool, c->f);
     } else if(c->type == CONSTANT_STRING) {
         return pool_register_string2(pool, c->s);
+    } else if(c->type == CONSTANT_UNDEFINED) {
+        /* write undefined with index 0 (and no type). Otherwise, the FlashPlayer 
+           seems to throw an "attempt to read out of bounds" exception */
+        return 0;
     } else if(!constant_has_index(c)) {
         return 1;
     } else {
@@ -1162,6 +1169,9 @@ void pool_read(pool_t*pool, TAG*tag)
        if(m.type==0x07 || m.type==0x0d) {
            int namespace_index = swf_GetU30(tag);
             m.ns = (namespace_t*)array_getkey(pool->x_namespaces, namespace_index);
+           if(!m.ns) {
+               fprintf(stderr, "Error: Illegal reference to namespace #%d in constant pool.\n", namespace_index);
+           }
             int name_index = swf_GetU30(tag);
             if(name_index) // 0 = '*' (any)
                m.name = pool_lookup_string(pool, name_index);