This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: tkinter - PhotoImage.zoom() causes segfault
Type: enhancement Stage: resolved
Components: Documentation, Tkinter Versions: Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: Varpu Rantala, docs@python, hcbd, python-dev, serhiy.storchaka, terry.reedy
Priority: normal Keywords: easy, patch

Created on 2015-12-26 23:16 by hcbd, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test.py hcbd, 2015-12-26 23:16 run test.py to crash python, be sure to point at an existing imagefile
mapbg.gif hcbd, 2015-12-27 14:33 the image used in test.py
test_issue25959.tcl serhiy.storchaka, 2015-12-27 16:09
tkinter_photo_zoom_doc.patch serhiy.storchaka, 2016-01-02 11:22 review
Messages (12)
msg257055 - (view) Author: hcdb (hcbd) Date: 2015-12-26 23:16
My 6 lines of code crash and cause a segmentation fault when using .zoom() on a PhotoImage in tkinter (run test.py)

tested and crashed in python 2.7.6, 2.7.9, 3.4.2 & 3.4.3 on linux mint 17.3 and debian jessie

ps. just learning to code python, so maybe i'm doing it wrong.
msg257058 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-12-27 00:22
Can't reproduce a crash. What is your OS? What versions of your Python and Tk? Can you provide your image?
msg257061 - (view) Author: hcdb (hcbd) Date: 2015-12-27 01:26
system 1:
os: Linux Mint 17.3 (64bit Mate)

python version: 2.7.6
python-tk version: 2.7.5-1ubuntu1 (according to packagemanager)

python3 version 3.4.3
python3-tk version: 3.4.3-1~14.04.2 (according to packagemanager)

running python in gdb on this system gives me these outputs:

(gdb) run test2.py
Starting program: /usr/bin/python test2.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff47ca700 (LWP 14639)]

Program received signal SIGSEGV, Segmentation fault.
memset () at ../sysdeps/x86_64/memset.S:80
80	../sysdeps/x86_64/memset.S: No such file or directory.
(gdb) backtrace
#0  memset () at ../sysdeps/x86_64/memset.S:80
#1  0x00007ffff66ce4ad in ?? () from /usr/lib/x86_64-linux-gnu/libtk8.6.so
#2  0x00007ffff66cffab in Tk_PhotoPutZoomedBlock ()
   from /usr/lib/x86_64-linux-gnu/libtk8.6.so
#3  0x00007ffff66cc12b in ?? () from /usr/lib/x86_64-linux-gnu/libtk8.6.so
#4  0x00007ffff62c8337 in TclNRRunCallbacks ()
   from /usr/lib/x86_64-linux-gnu/libtcl8.6.so
#5  0x00007ffff6982030 in ?? () from /usr/lib/python2.7/lib-dynload/_tkinter.so
#6  0x000000000049968d in PyEval_EvalFrameEx ()
#7  0x00000000004a090c in PyEval_EvalCodeEx ()
#8  0x0000000000499a52 in PyEval_EvalFrameEx ()
#9  0x00000000004a1634 in ?? ()
#10 0x000000000044e4a5 in PyRun_FileExFlags ()
#11 0x000000000044ec9f in PyRun_SimpleFileExFlags ()
#12 0x000000000044f904 in Py_Main ()
#13 0x00007ffff7818ec5 in __libc_start_main (main=0x44f9c2 <main>, argc=2, 
    argv=0x7fffffffe0b8, init=<optimized out>, fini=<optimized out>, 
    rtld_fini=<optimized out>, stack_end=0x7fffffffe0a8) at libc-start.c:287
#14 0x0000000000578c4e in _start ()
---------------------------------------

system2:
os: Debian Jessie (Gnome3)

python version:2.7.9
python-tk version:2.7.8-2+b1

python3 version:3.4.2
python3-tk version: 3.4.2-1+b1

output from gdb from this system (gui.py is my program that does the same as test.py only loads more widgets:

Starting program: /usr/bin/python gui.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff435d700 (LWP 10798)]

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff64ba07b in Tk_PhotoPutZoomedBlock ()
   from /usr/lib/x86_64-linux-gnu/libtk8.6.so
(gdb) backtrace
#0  0x00007ffff64ba07b in Tk_PhotoPutZoomedBlock ()
   from /usr/lib/x86_64-linux-gnu/libtk8.6.so
#1  0x00007ffff64b6171 in ?? () from /usr/lib/x86_64-linux-gnu/libtk8.6.so
#2  0x00007ffff6092a87 in TclNRRunCallbacks ()
   from /usr/lib/x86_64-linux-gnu/libtcl8.6.so
#3  0x00007ffff6ae53c0 in ?? () from /usr/lib/python2.7/lib-dynload/_tkinter.so
#4  0x00000000004c9e05 in PyEval_EvalFrameEx ()
#5  0x00000000004c87a1 in PyEval_EvalCodeEx ()
#6  0x00000000004ca31a in PyEval_EvalFrameEx ()
#7  0x00000000004c87a1 in PyEval_EvalCodeEx ()
#8  0x00000000004ca31a in PyEval_EvalFrameEx ()
#9  0x00000000004ca592 in PyEval_EvalFrameEx ()
#10 0x00000000004ca592 in PyEval_EvalFrameEx ()
#11 0x00000000004ca592 in PyEval_EvalFrameEx ()
#12 0x00000000004e5fe8 in ?? ()
#13 0x00000000005045d8 in ?? ()
#14 0x00000000004eb950 in PyInstance_New ()
#15 0x00000000004caaa1 in PyEval_EvalFrameEx ()
#16 0x00000000004c87a1 in PyEval_EvalCodeEx ()
#17 0x00000000005030ef in ?? ()
#18 0x00000000004f8c72 in PyRun_FileExFlags ()
#19 0x00000000004f7d77 in PyRun_SimpleFileExFlags ()
#20 0x00000000004982f2 in Py_Main ()
---Type <return> to continue, or q <return> to quit---
#21 0x00007ffff6f14b45 in __libc_start_main (main=0x497d80 <main>, argc=2, 
    argv=0x7fffffffe3b8, init=<optimized out>, fini=<optimized out>, 
    rtld_fini=<optimized out>, stack_end=0x7fffffffe3a8) at libc-start.c:287
#22 0x0000000000497ca0 in _start ()
msg257067 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-12-27 07:15
Thank you. Can you provide your image?
msg257077 - (view) Author: hcdb (hcbd) Date: 2015-12-27 14:33
yes I can provide my image

the original image was a .png but I converted it to .gif using GIMP

alternative download here:
image:  http://tsfl.nl/mapbg.gif
script: http://tsfl.nl/test.py
msg257079 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-12-27 16:09
Arguments for PhotoImage.zoom() are zoom factors, not the dimension of the result. In you case you are trying to create an image with size 54000x29964 pixels. This is over 1.6 gigapixels.

Here is pure Tcl equivalent of Python example. It should reproduce the crash.

There is a documentation bug in Tkinter. PhotoImage.zoom() docstring is not clear. This can and should be fixed.

There is a bug in Tk. It shouldn't crash processing image even if the result has incredible size. But we can't do anything with this bug besides reporting to mainstream.

Requalified this issue as easy documentation issue.
msg257080 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-12-27 16:35
Opened Tk ticket: http://core.tcl.tk/tk/info/607ffb053c783490 .
msg257319 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-01-01 23:52
Tk ticket update: '''aspect added on 2015-12-28 00:30:33:

I can reproduce this crash on 8.5.18 and 8.6.4, but it appears to be fixed in trunk:  "not enough free memory for image buffer".'''

We should see fix in 3.6.

Doc addition is not exactly trivial, as there is only the barest mention of images in https://docs.python.org/3/library/tkinter.html#images.
msg257344 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-01-02 11:22
I think it is enough just to update a docstring. Adding comprehensive RST documentation for Tkinter widgets is different issue.
msg261570 - (view) Author: Varpu Rantala (Varpu Rantala) * Date: 2016-03-11 13:43
crashes also with Python 3.5.0 (Mac OS X 10.11.3) when x and y are the following or bigger, but works when they are smaller. Tried it with the mapbe.gif image (size 1000 x 681). 

30, 27 
31, 26 
32, 25 
33, 24 
34, 24 
35, 23 
36, 22 
37, 22 
38, 22 
39, 21 
40, 20
msg261597 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-03-11 20:31
New changeset 1e7c388dc3c5 by Terry Jan Reedy in branch '2.7':
Issue 25959: Explain in docstring that PhotoImage.zoom arguments are
https://hg.python.org/cpython/rev/1e7c388dc3c5

New changeset 7474695874d9 by Terry Jan Reedy in branch '3.5':
Issue 25959: Explain in docstring that PhotoImage.zoom arguments are
https://hg.python.org/cpython/rev/7474695874d9
msg261598 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-03-11 20:41
Thanks Terry.
History
Date User Action Args
2022-04-11 14:58:25adminsetgithub: 70147
2016-03-11 20:41:30serhiy.storchakasetmessages: + msg261598
2016-03-11 20:32:28terry.reedysetstatus: open -> closed
resolution: fixed
stage: commit review -> resolved
2016-03-11 20:31:44python-devsetnosy: + python-dev
messages: + msg261597
2016-03-11 20:21:13terry.reedysetassignee: docs@python -> terry.reedy
stage: needs patch -> commit review
2016-03-11 13:43:40Varpu Rantalasetnosy: + Varpu Rantala
messages: + msg261570
2016-01-02 11:22:03serhiy.storchakasetfiles: + tkinter_photo_zoom_doc.patch
keywords: + patch
messages: + msg257344
2016-01-01 23:52:51terry.reedysetnosy: + terry.reedy
messages: + msg257319
2015-12-27 16:35:19serhiy.storchakasetmessages: + msg257080
2015-12-27 16:09:59serhiy.storchakasetfiles: + test_issue25959.tcl


assignee: docs@python
keywords: + easy
stage: needs patch
versions: + Python 3.5, Python 3.6, - Python 3.4
nosy: + docs@python
messages: + msg257079
components: + Documentation
type: crash -> enhancement
2015-12-27 14:33:39hcbdsetfiles: + mapbg.gif

messages: + msg257077
2015-12-27 07:15:09serhiy.storchakasetmessages: + msg257067
2015-12-27 01:26:08hcbdsetmessages: + msg257061
2015-12-27 00:22:36serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg257058
2015-12-26 23:16:11hcbdcreate