Calling `toBase64` on a CFML Image (`ImageNew`) is not idempotent

Description

Calling toBase64 on a CFML image (created with ImageNew) does not return the same value on the first call as with subsequent calls.

Here’s a gist on TryCF showing the issue: https://trycf.com/gist/020405d3210659a68da72999afd40bee/acf2018?theme=monokai

<cfscript> imageIO = createObject( "java", "javax.imageio.ImageIO" ); imageUrl = createObject( "java", "java.net.URL" ).init( "https://www.lucee.org/assets/img/logo.png" ); bufferedImage = imageIO.read( imageUrl ); cfmlImage = imageNew( bufferedImage ); firstBase64 = toBase64( cfmlImage ); secondBase64 = toBase64( cfmlImage ); </cfscript> <div> <h3>`toBase64` non-idempotent example</h3> <p>Calling `toBase64` on an image should return the same string every time.</p> <p>Run this on Adobe 2018 engines to see it working correctly.</p> <p>Run it on Lucee 5 to see it failing.</p> <cfoutput> <h4>Are the two `toBase64` calls the same? #uCase( yesNoFormat( firstBase64 == secondBase64 ) )#</h4> </cfoutput> <cfif firstBase64 NEQ secondBase64> <cfdump var="#firstBase64#" expand="false" label="First toBase64 call" /> <cfdump var="#secondBase64#" expand="false" label="Second toBase64 call" /> </cfif> </div>

For what it is worth, it is the second value that is correct.

Environment

None

Activity

Show:

Pothys - MitrahSoft 3 July 2024 at 07:37

Nice catch, . It seems to be fixed and works as expected with Lucee version 6.0.4.1-SNAPSHOT.

Zac Spitzer 2 July 2024 at 22:24

I think this is now working correctly? the test passes for me with 6.0.4.1-SNAPSHOT?

Zac Spitzer 1 June 2022 at 07:16

Pothys - MitrahSoft 26 April 2022 at 11:25

I've checked this ticket and confirmed the issue happened on the lucee version 5.3.9.131-SNAPSHOT. Using toBase64() to get the base64 value of the image which is the result of imageNew() didn't return the same result. Seems ACF works fine. Also if the image created by the imageNew() with URL means it works fine in lucee too.

But adding a dump (writeDump(cfmlImage)) after the imageNew(), toBase64 returns the same values.
https://trycf.com/gist/b45a0eb6eea76c38f2d683684eb0347b/lucee5?theme=monokai

 

<cfscript> imageIO = createObject( "java", "javax.imageio.ImageIO" ); imageUrl = createObject( "java", "java.net.URL" ).init( "https://www.lucee.org/assets/img/logo.png" ); bufferedImage = imageIO.read( imageUrl ); cfmlImage = imageNew( bufferedImage ); writeDump(var=cfmlImage, expand=false ); // dump the image object toBase64 returns the same values secondBase64 = toBase64( cfmlImage ); firstBase64 = toBase64( cfmlImage ); writeDump("Are the two `toBase64` calls the same? " & uCase( yesNoFormat( firstBase64 == secondBase64 ) )); </cfscript>

I added a testcase to this ticket

Pull Request: https://github.com/lucee/Lucee/pull/1624

Unresolved

Details

Assignee

Reporter

Priority

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Created 25 April 2022 at 16:36
Updated 25 March 2025 at 19:55

Flag notifications