Tk Source Code

View Ticket
Login
Ticket UUID: 2809525
Title: Abort on overlong color name
Type: Bug Version: obsolete: 8.6b1
Submitter: andygoth Created on: 2009-06-20 17:18:22
Subsystem: 30. Color Names Assigned To: jan.nijtmans
Priority: 9 Immediate Severity:
Status: Closed Last Modified: 2014-03-13 09:08:31
Resolution: Fixed Closed By: nijtmans
    Closed on: 2012-03-21 22:23:53
Description:
. configure -bg [string repeat x 65536]

causes the interpreter to abort with:

X Error of failed request:  BadLength (poly request too large or internal Xlib length error)
  Major opcode of failed request:  92 (X_LookupColor)
  Serial number of failed request:  3231
  Current serial number in output stream:  3231
User Comments: nijtmans added on 2012-03-22 05:23:53:

allow_comments - 1

Fixed for 8.6, 8.5 and 8.4.

nijtmans added on 2012-03-22 03:43:41:

allow_comments - 0

Now try:
% image create photo
% image1 put [string repeat x 65536]
>   xxxxxxxxxxxxxx.......   xxxxxxxxx
X Error of failed request:  BadLength (poly request too large or internal Xlib length error)
  Major opcode of failed request:  92 (X_LookupColor)
  Serial number of failed request:  91
  Current serial number in output stream:  91

Explanation: There are two ways to parse a color. One
is through TkpGetColor, which was patched to protect
against overly long strings. However, there are other
places in Tk where XParseColor is called directly.

Solution: move the protection to wrapper functions
TkParseColor and TkAllocNamedColor, so everywhere
in Tk one of those functions is used it will
be protected.

dkf added on 2009-10-26 00:17:54:

allow_comments - 1

Fixed for 8.6, 8.5 and 8.4.

andygoth added on 2009-06-21 21:47:18:
I agree completely.  Pick any limit that's at least as long as the longest known color name, but far shorter than the 64K X11 threshold.  And the reason I'm reporting is because of the safe interpreter problem.

dkf added on 2009-06-21 19:29:17:
We could just restrict color names to 64 bytes long; nobody does color names longer than that.

(Prio boosted because this is trivial to use as a DoS attack in safe interpreters.)