Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2020-03-28
15:35 • Closed ticket [ffeb2097af]: binary decode base64 errors on invalid chars inste... artifact: 04ae03a2c9 user: dgp
15:35
[ffeb2097af] Restore the standard and original practice of ignoring invalid characters when decoding... check-in: 0382197472 user: dgp tags: core-8-6-branch
03:34 • Ticket [ffeb2097af] binary decode base64 errors on invalid chars instead of ig... artifact: 01e5d1bacd user: dgp
03:31 • Ticket [ffeb2097af]: 3 changes artifact: 1edbc4a58d user: dgp
02:47 • Ticket [ffeb2097af]: 3 changes artifact: c5d24c2a45 user: dgp
2020-03-27
23:39 • Ticket [ffeb2097af]: 3 changes artifact: cd1edf80b7 user: aku
23:34 • Ticket [ffeb2097af]: 3 changes artifact: 7b324ab83a user: dgp
23:31 • Ticket [ffeb2097af]: 3 changes artifact: da64668c62 user: dgp
22:28 • New ticket [ffeb2097af]. artifact: 38f2abdb3b user: dgp

[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.