Tuesday, January 21, 2025
HomeJavaScriptUnusual ___IMPLICITARRYSTRUCTVAR Conduct In ColdFusion

Unusual ___IMPLICITARRYSTRUCTVAR Conduct In ColdFusion


Whereas James England and I had been engaged on Dig Deep Health, we got here throughout a somewhat mysterious ColdFusion conduct. The native reminiscence leak detection mechanism began reporting the existence of an surprising variable known as, ___IMPLICITARRYSTRUCTVAR0. I would by no means seen this earlier than; however Google pointed me to one thing Adam Cameron talked about it on an outdated Adobe ColdFusion discussion board publish from 2012. Apparently implicit struct and array notation has been creating these hidden variables since ColdFusion 9.

immediately-invoked operate expression (IIFE) which executes two nonsense ternary operators. Then, we will output the variables scope.

<cfscript>

	(() => {

		var arrayValue = false
			? "yay"
			: []
		;
		var structValue = false
			? "yay"
			: {}
		;

		for ( key in variables.keyArray() ) {

			// Observe: wrapping output in array as a result of dumping-out a struct will disguise any
			// key that accommodates the substring "___IMPLICITARRYSTRUCTVAR".
			writeDump([ key, variables[ key ] ]);

		}

	})();

</cfscript>

After the 2 ternary operators are executed, I output the keys within the variables scope. After I do that, I am wrapping the key-value pairs in an array since ColdFusion will actively disguise any struct entry during which the important thing accommodates the substring, ___IMPLICITARRYSTRUCTVAR. That is in all probability why I’ve by no means seen this earlier than.

Once we run this Adobe ColdFusion 2023 code, we get the next output:

A CFDump of the variables scope shows several hidden variables.

Discover that ColdFusion has created two hidden variables referring to the implicit information construction notation: ___IMPLICITARRYSTRUCTVAR0 and ___IMPLICITARRYSTRUCTVAR1. These variables comprise the results of the implicit information construction expression execution.

the ++ and -- operators are unsafe to make use of with regards to a shared reminiscence house.

What’s probably taking place is that simply earlier than one of many iterations goes to increment the .depend key, a parallel iteration thread has simply overwritten the shared ___IMPLICITARRYSTRUCTVAR0 variable, thereby clobbering the .depend key for the opposite thread.

To work round this bug, all it’s important to do is transfer the implicit struct expression out of the ternary operator. A technique to do this is to exchange the ternary operator with an if/else management move:

<cfscript>

	arrayNew( 1 )
		// Create a group that's giant(ish).
		.resize( 1000 )
		.set( 1, 1000, 1 )
		// Iterate over the gathering utilizing PARALLEL THREADS.
		.every(
			() => {

				// By shifting the implicit struct OUT of the ternary operator and into an
				// if/else block, we take away the implicit variable creation.
				if ( false ) {

					var worth = "yay";

				} else {

					var worth = { depend: 0 };
				}

				// Increment LOCAL worth.
				worth.depend++;

			},
			true,
			20
		)
	;

	// Output the personal web page variables.
	for ( key in variables.keyArray() ) {

		writeDump([ key, variables[ key ] ]);

	}

</cfscript>

This time, once we execute this Adobe ColdFusion 2023 code, it executes with out error. And, the resultant web page is clean since no ___IMPLICITARRYSTRUCTVAR0 variable is created within the variables scope.

Loopy stuff! I do not know if that is restricted to the ternary operator; however, it is the one place that I’ve seen this conduct present itself.

Wish to use code from this publish?
Take a look at the license.


https://bennadel.com/4748

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments