Bug in CF9: values for unique struct keys referenced and overwritten by other keys.

Posted by Gin Doe on Stack Overflow See other posts from Stack Overflow or by Gin Doe
Published on 2010-01-29T19:12:35Z Indexed on 2010/03/16 10:26 UTC
Read the original article Hit count: 337

Filed under:
|

We've run into a serious issue with CF9 wherein values for certain struct keys can be referenced by other keys, despite those other keys never being set. See the following examples:

Edit: Looks like it isn't just something our servers ate. This is Adobe bug-track ticket 81884: http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=81884.

<cfset a = { AO = "foo" } />
<cfset b = { AO = "foo", B0 = "bar" } />

<cfoutput>
The following should throw an error. Instead both keys refer to the same value.
<br />Struct a: <cfdump var="#a#" />
<br />a.AO: #a.AO#
<br />a.B0: #a.B0#
<hr />
The following should show a struct with 2 distinct keys and values. Instead it contains a single key, "AO", with a value of "bar".
<br />Struct b: <cfdump var="#b#" />

This is obviously a complete show-stopper for us. I'd be curious to know if anyone has encountered this or can reproduce this in their environment. For us, it happens 100% of the time on Apache/CF9 running on Linux, both RH4 and RH5. We're using the default JRun install on Java 1.6.0_14.

To see the extent of the problem, we ran a quick loop to find other naming sequences that are affected and found hundreds of matches for 2 letter key names. A similar loop found more conflicts in 3 letter names.

<cfoutput>Testing a range of affected key combinations. This found hundreds of cases on our platform. Aborting after 50 here.</cfoutput>
<cfscript>
teststring = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
stringlen = len(teststring);
matchesfound = 0;
matches = "";

for (i1 = 1; i1 <= stringlen; i1++) {
    symbol1 = mid(teststring, i1, 1);
    for (i2 = 1; i2 <= stringlen; i2++) {
        teststruct = structnew();
        symbol2 = mid(teststring, i2, 1);
        symbolwhole = symbol1 & symbol2;
        teststruct[ symbolwhole ] = "a string";

        for (q1 = 1; q1 <= stringlen; q1++) {
            innersymbol1 = mid(teststring, q1, 1);
            for (q2 = 1; q2 <= stringlen; q2++) {
                innersymbol2 = mid(teststring, q2, 1);
                innersymbolwhole = innersymbol1 & innersymbol2;
                if ((i1 != q1 || i2 != q2) && structkeyexists(teststruct, innersymbolwhole)) {
                    // another affected pair of keys!
                    writeoutput ("<br />#symbolwhole# = #innersymbolwhole#");
                    if (matchesfound++ > 50) {
                        // we've seen enough
                        abort;
                    }
                }
            }
        }
    }
}
</cfscript>

And edit again: This doesn't just affect struct keys but names in the variables scope as well. At least the variables scope has the presence of mind to throw an error, "can't load a null":

<cfset test_b0 = "foo" />
<cfset test_ao = "bar" />
<cfoutput>
test_b0: #test_b0#
<br />test_ao: #test_ao#
</cfoutput>

© Stack Overflow or respective owner

Related posts about coldfusion

Related posts about bug