Title: Tbuffer in turtle allows negative size
Type: Stage: patch review
Components: Versions: Python 3.4, Python 3.5, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: Lita.Cho, jesstess, python-dev, rhettinger
Priority: high Keywords: needs review, patch

Created on 2014-06-25 07:10 by Lita.Cho, last changed 2014-07-21 04:33 by rhettinger. This issue is now closed.

File name Uploaded Description Edit
undobuffer_fix.patch Lita.Cho, 2014-06-25 16:47
Messages (9)
msg221530 - (view) Author: Lita Cho (Lita.Cho) * Date: 2014-06-25 07:10
Currently, you can set the undobuffer size to negative numbers. Aka, the Tbuffer can be set to negative.

s = turtle.Screen()
raw = turtle.RawTurtle(s)
raw.undobuffer.bufsize == -10 <-- returns True

This should not be possible. Tbuffer should not be allowed to have negative inputs. If the value is less than 0, it should just default to 0 or None. Otherwise, when you call undo, turtle just crashes.
msg221556 - (view) Author: Lita Cho (Lita.Cho) * Date: 2014-06-25 16:47
Here is a patch for this bug. Basically, when a user gives 0 and below, it doesn't create a TBuffer. Then "undo" does the right thing.
msg221571 - (view) Author: Lita Cho (Lita.Cho) * Date: 2014-06-25 20:07
I should clarify. The right thing being that calling undo does nothing, and turtle keeps on running. This is the default behaviour when setundobuffer is called with no size.
msg222224 - (view) Author: Lita Cho (Lita.Cho) * Date: 2014-07-03 21:43
Hey Raymond, just wanted to ping you to see if you had a chance to review this patch yet. Thanks!
msg222231 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-07-03 22:24
I looked at this and marked it as high priority (crashes are an unacceptable outcome).  The patch looks fine but I haven't had a chance to test it yet.  If it passes muster, I'll apply it shortly (I'm overseas traveling this week).

In the meantime, can you mark the "versions" in the tracker so I'll know in advance whether this applies to 2.7, 3.4 and 3.5?  Thanks.
msg222810 - (view) Author: Lita Cho (Lita.Cho) * Date: 2014-07-11 23:00
Hi Raymond! Just wanted to check if you had time to test this yet. I ran the tests through the Turtle tests I wrote (issue21914), but those are still pending approval.

This is off topic, but I also didn't realize till now that you gave a talk about "Transforming Code into Beautiful, Idiomatic Python", which is super awesome! Getting a patch reviewed by you is super exciting! :)
msg223556 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-07-21 04:26
New changeset 847a0e74c4cc by Raymond Hettinger in branch '2.7':
Issue #21868: Prevent turtle crash due to invalid undo buffer size.
msg223557 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-07-21 04:31
New changeset 02b25ec13c94 by Raymond Hettinger in branch '3.4':
Issue #21868: Prevent turtle crash due to invalid undo buffer size.
msg223558 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-07-21 04:33
Thanks for the patch Lita.  This was a nice fix.
Date User Action Args
2014-07-21 04:33:08rhettingersetstatus: open -> closed
resolution: fixed
messages: + msg223558
2014-07-21 04:31:43python-devsetmessages: + msg223557
2014-07-21 04:26:14python-devsetnosy: + python-dev
messages: + msg223556
2014-07-17 04:39:06jesstesssetkeywords: + needs review
stage: patch review
2014-07-11 23:00:57Lita.Chosetmessages: + msg222810
2014-07-03 22:35:59Lita.Chosetversions: + Python 2.7
2014-07-03 22:35:47Lita.Chosetversions: + Python 3.4, Python 3.5
2014-07-03 22:24:14rhettingersetmessages: + msg222231
2014-07-03 21:43:48Lita.Chosetmessages: + msg222224
2014-06-25 20:07:48Lita.Chosetmessages: + msg221571
2014-06-25 20:01:30rhettingersetpriority: normal -> high
assignee: rhettinger

nosy: + rhettinger
2014-06-25 16:47:16Lita.Chosetfiles: + undobuffer_fix.patch
keywords: + patch
messages: + msg221556
2014-06-25 07:10:34Lita.Chosetnosy: + jesstess
2014-06-25 07:10:25Lita.Chocreate