[binary decode base64] errors on invalid chars instead of ignoring them
Closed / Fixedffeb2097afc82afd346901bde7e3db5d898ce993Created 7 years agoUpdated 7 years ago
Descriptionplain2020-03-27 22:28:56
Another inconsistency between [binary decode base64] and the base64 package that TIP 317 suggested was the intended model. % package require base64 2.4.2 % base64::decode [base64::encode -maxlen 3 -wrapchar : abc] abc % binary decode base64 [binary encode base64 -maxlen 3 -wrapchar : abc] invalid base64 character ":" at position 3
Referenced by1
0382197472[ffeb2097af] Restore the standard and original practice of ignoring invalid characters when decoding base64. Error only in -strict mode. See RFC 2045. check-in2020-03-28 15:35:12
dgpplain2020-03-27 23:31:37
[base64::decode] accepts no options. [binary decode base64] has an optional option -strict that makes it reject whitespace too. % binary decode base64 -strict [binary encode base64 -maxlen 3 abc] invalid base64 character " " at position 3 TIP 317 apparently invented this without description. It's difficult to see what use it meets.
dgpplain2020-03-27 23:34:41
Comments in the base64 package mention RFC 2045. https://datatracker.ietf.org/doc/rfc2045/?include_text=1 It says " Any characters outside of the base64 alphabet are to be ignored in base64-encoded data."
akuplain2020-03-27 23:39:40
The comment in Tcllib referencing the RFC is ``` # RFC 2045 says that line breaks and other characters not part # of the Base64 alphabet must be ignored, and that the decoder # can optionally emit a warning or reject the message. We opt # not to do so, but to just ignore the character. ``` at the bottom of `base64.tcl`. My opinion is that the Tcl command should reject any bogus characters only in -strict mode, and in regular mode ignore them like the Tcllib command does.
dgpplain2020-03-28 02:47:04
The tests in the test suite that examine the rejection of characters outside the Base64 alphabet all include the -strict option. At least mild evidence this is a bug rather than a design.
dgpplain2020-03-28 03:31:05
The original implementation was consistent with the base64 package. A "regression" (an intentional change really) came in https://core.tcl-lang.org/tcl/info/1d99671194f9d92f which aimed to stop a segfault reported here https://core.tcl-lang.org/tcl/info/2380293
dgpplain2020-03-28 03:34:07
I note that the segfault and the tests for it were in the uuencode decoder, but the base64 decoder got changed too. This is at least worth another look.
dgpplain2020-03-28 15:35:33
Fixed.
Log in (anonymous is fine) to add a comment.