Tk Source Code

View Ticket
Login
Ticket UUID: bffa794b1b50745e0cf81c860b0bcbf36ccfb21a
Title: BadAlloc (insufficient resources for operation) in the grid command
Type: Bug Version: 8.5.19
Submitter: storchaka Created on: 2016-04-08 17:03:02
Subsystem: 49. [grid] Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2020-04-23 21:26:06
Resolution: None Closed By: nobody
    Closed on:
Description:

Following script

label .a -text [string repeat 0 0x1000]
grid configure .a -row 1 -column 1

causes a crash wish following error messages:

X Error of failed request:  BadAlloc (insufficient resources for operation)
  Major opcode of failed request:  53 (X_CreatePixmap)
  Serial number of failed request:  102
  Current serial number in output stream:  104

Any multiplier between 0x1000 and 0x1fff cause a crash. With multipliers >= 0x2000 only the number of zeros over 0x2000 is displayed. Multiplier between 0x3000 and 0x3fff crashes again.

The width of "0" in the used font is 8 pixels. Seems there is an integer overflow.

User Comments: fvogel added on 2020-04-23 21:26:06:

There are several (old) tickets in this repository showing various issues boiling down to dimensions exceeding what a short int can handle (+/-32767). Not all of them are pathological though.

A non exhaustive list is [3307625fff], [2421792fff] and [770578fff]. In the latter ticket, a comment by dkf on 2004-02-16 says it all about the philosophy in those cases.


chrstphrchvz added on 2020-04-23 17:43:20:

This crash still happens on 8.6.10, and will likely continue to do so. The crash occurs when Tk_GetPixmap() (a wrapper for XCreatePixmap()) is called from TkpDisplayButton() (tkUnixButton.c), using the width of the label: 0x1000 * 8 = 0x8000 = 32768 (plus any borders or padding), which exceeds 32767—the maximum value for signed 16 bit integers, and the inherent limit for dimensions in X11. (Once the width exceeds 65535, as for 0x2000 * 8 = 65536, the width is interpreted as having wrapped around 0.)

I don't know whether Tk should clip dimensions to avoid crashes, or argue that these cases are too unusual to merit workarounds. Non-X11 windowing systems appear to lack limitations like this one, and X11 is simply no longer the windowing system of the future.


fvogel added on 2016-04-08 17:10:37:
Doesn't crash on Windows (Vista).