Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2008-12-16
00:15 • Closed ticket [2380293fff]: binary decode uuencode foo --> segfault plus ... artifact: b6a7d1acaf user: ferrieux
00:15 • Ticket [2380293fff]: 4 changes artifact: bf419d8371 user: ferrieux
2008-12-12
15:47 • Ticket [2380293fff]: 4 changes artifact: 2af52896b3 user: ferrieux
07:11 • Add attachment uu.patch to ticket [2380293fff] artifact: 207f271541 user: ferrieux
07:11 • Ticket [2380293fff] binary decode uuencode foo --> segfault status still ... artifact: 9c99837878 user: ferrieux
2008-12-03
16:01 • Ticket [2380293fff]: 3 changes artifact: 24ea495bb3 user: dkf
00:02 • New ticket [2380293fff]. artifact: 3f1d582980 user: duoas

binary decode uuencode foo --> segfault

Closed / Fixed2380293fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 18 years ago
Descriptionplain2008-12-03 00:02:04
Yep, trying to decode an invalid string causes a segfault (meaning Tcl crashes and burns).

To replicate, start up tclsh86 and type:

  binary decode uuencode foo

Hope this helps.
dkf Ticket [2380293fff]: 3 changes [History diff]2008-12-03 16:01:07
ferrieuxplain2008-12-12 07:11:01
File Added - 304973: uu.patch

This is due to an off-by-one length computation yielding -1 in a non-strict case.
Knowing nothing of the uuencode algorithm I cannot fix it properly; however, the attached patch fixes the crash by saturating the size to nonnegative values.
File Added: uu.patch
ferrieuxplain2008-12-12 15:47:08
OK now I know the algorithm. The off-by-one is the visible part of a larger iceberg: the "cut" variable counts missing bytes in the source (base 64) stream, and is wrongly translated 1-to-1 into missing bytes in the decoded stream. So there's a systematic error of factor 4/3 (since a "cut++" should only count as removing 6 bits).

However, I believe the very principle of allowing non-strict uudecoding is flawed. Indeed, a "BadUU" byte in the middle is just skipped, but I wonder about the perturbation process that this is modelling. Indeed if random bytes are inserted here and there, only those which are fortunately outside the 32..96 range will be filtered out. So I cannot imagine a practical situation where an uuencoded stream would be decoded non-strictly... So the quick patch is enough to avoid crashes, the only remaining error being truncated results for error-filled inputs.

Pat, your feeling ?
ferrieuxplain2008-12-16 00:15:33
After a chat with Kevin, only answerer, it appears that non-strictness has an obvious usecase with randomly interspersed whitespace. That was the perturbation process I was after.
But it is also clear that any other kind of unexpected character is fishy and should raise an error.
Just committed this change:
 - fix the off-by-one bug that caused crashes or truncation (which is not 4/3 but only of one char at maximum, because it can occur only in the last 4-byte chunk)
 - redefine the non-strict contract to allow only whitespace as defined by the isspace() function.
ferrieux Closed ticket [2380293fff]. [History diff]2008-12-16 00:15:34
Log in (anonymous is fine) to add a comment.

Attachments: