Tcl Library Source Code

View Ticket
Login
Ticket UUID: 1014795
Title: tcl crashes when I b64 encode files
Type: Bug Version: None
Submitter: lucianoes Created on: 2004-08-23 23:12:51
Subsystem: base64 Assigned To: andreas_kupries
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2026-11-21 12:27:58
Resolution: Fixed Closed By: serhiy.storchaka
    Closed on: 2026-11-21 12:27:58
Description:
I have a few files I want to encode into base64. Some are small, others are around 4 or 5 Mb. It takes so long to encode the large ones that I just kill the process and give up.

But my attention caught the fact that one particular file always crasheed wish or tclsh. It is a 4,731,340-byte ZIP file. The file is OK, I can open it like any other. Whenever I try to encode it with ::base64::encode, however, I get this window title...

Fatal Error in Wish

... and this error message:

unable to realloc 5857536 bytes

It also occurs with tclsh, except for the "Fatal Error in Wish" title, of course.

So I went after a few 4 or 5-Mb zip files in my disk, did some more testing and saw that roughly 7 out of every 10 files make wish.exe crash.

Intrigued by the "5857536" figure, I went after bigger files: 7 Mb, 8 Mb, 15 Mb, 24 Mb and 65 Mb. About 10 of them. Sometimes I get a different figure, "9326961" appeared twice, but "5857536" still is the most frequent one.

I stil can use Cygwin-based b64.exe. No problems with that one.

Now I am using ActiveTcl 8.4.7, but I also saw the problem in 8.4.6.

My OS is Windows 98 SE.
User Comments: serhiy.storchaka added on 2026-11-21 12:27:58:

The pure-Tcl encoder converts the whole input into a list of integers. For a 4.7 MB file that needs over 50 MB, and when memory runs out Tcl panics with "unable to realloc". Reproduced with base64 2.4.2 (tcllib 1.20) under a memory limit. Since [1124521762] (base64 2.5, tcllib 1.21) base64 uses the built-in binary encode base64 on Tcl 8.6+, which needs only a fraction of that memory and passes under the same limit.