binaryDecode() and toBinary() are decoding invalid base64 date

Description

The binaryDecode() & toBinary() functions are decoding invalid base64 strings into binary objects. I would except an invalid base64 string to throw an exception, which is what happens in ACF 10+.

For example:

binaryDecode("@@@@", "base64"); toBinary("@@@@");

I would expect both of these lines to fail, but instead Lucee happily converts these strings to an empty binary object. If you decode the strings back to Base64, you get an empty string:

binaryEncode(binaryDecode("@@@@", "base64"), "base64"); // empty string toBase64(toBinary("@@@@")); // empty string

Here's a Gist that shows the behavior:
https://www.trycf.com/gist/29932185013dddf447c130f1362452d9/lucee5?theme=monokai

If you run the code under an ACF engine, you will see that the "@@@@" string throws an exception, where as Lucee happily converts the invalid base64 string.

If you're on Java 8, you can run the following and see that @@@@ would throw an exception:

invalidBase64 = "@@@@"; Base64 = createObject("java", "java.util.Base64"); Decoder = Base64.getDecoder(); writeOutput(Decoder.decode(invalidBase64));

Environment

CentOS 7
Tomcat 9.0.37
Lucee 5.3.6.61

Activity

Pothys - MitrahSoft 
19 January 2022 at 13:45

I've checked this ticket and using precise argument in binaryDecode() still has incompatibility with ACF.
Please see https://luceeserver.atlassian.net/browse/LDEV-3818?focusedCommentId=50144 for examples, that work in lucee and throws an error in ACF.

Zac Spitzer 
17 January 2022 at 16:12
(edited)

https://github.com/lucee/Lucee/commit/a02d6452301b50964dd2b2d09c28ae6a4e84c245

percise is spelt precise

test is also failing

[java] [script] Errored: test.functions.BinaryDecode.valid characters, valid length ---> variable [VALUE] doesn't exist [java] [script] at [java] [script] C:\work\lucee\test\functions\BinaryDecode.cfc:45

Michael Offner 
17 January 2022 at 15:34

we can consider set tthe default behaviour of this function to true with Lucee 6

Michael Offner 
17 January 2022 at 15:34

added new argument “percise“ to the function “binaryDecode“ that wehn set to true, does work as ACF in the above examples from .

Fixed

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

Sprint

Affects versions

Created 2 September 2020 at 14:17
Updated 19 January 2023 at 06:46
Resolved 17 January 2022 at 15:08