From 79746426c439a8a163d95381ffffa1b2fd34348e Mon Sep 17 00:00:00 2001 From: Ned Deily Date: Wed, 14 Sep 2011 14:49:14 -0700 Subject: [PATCH] Issue #9871: Prevent IDLE 3 crash when given byte stings with invalid hex escape sequences, like b'\x0'. (Original patch by Claudiu Popa.) --- Lib/idlelib/PyShell.py | 6 +++--- Lib/idlelib/ScriptBinding.py | 8 ++++---- Misc/ACKS | 1 + Misc/NEWS | 4 ++++ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py index da747290996..43e08f2c78d 100644 --- a/Lib/idlelib/PyShell.py +++ b/Lib/idlelib/PyShell.py @@ -643,9 +643,9 @@ class ModifiedInterpreter(InteractiveInterpreter): text = tkconsole.text text.tag_remove("ERROR", "1.0", "end") type, value, tb = sys.exc_info() - msg = value.msg or "" - lineno = value.lineno or 1 - offset = value.offset or 0 + msg = getattr(value, 'msg', '') or value or "" + lineno = getattr(value, 'lineno', '') or 1 + offset = getattr(value, 'offset', '') or 0 if offset == 0: lineno += 1 #mark end of offending line if lineno == 1: diff --git a/Lib/idlelib/ScriptBinding.py b/Lib/idlelib/ScriptBinding.py index 915e56e40fb..26becce0182 100644 --- a/Lib/idlelib/ScriptBinding.py +++ b/Lib/idlelib/ScriptBinding.py @@ -101,10 +101,10 @@ class ScriptBinding: try: # If successful, return the compiled code return compile(source, filename, "exec") - except (SyntaxError, OverflowError) as value: - msg = value.msg or "" - lineno = value.lineno or 1 - offset = value.offset or 0 + except (SyntaxError, OverflowError, ValueError) as value: + msg = getattr(value, 'msg', '') or value or "" + lineno = getattr(value, 'lineno', '') or 1 + offset = getattr(value, 'offset', '') or 0 if offset == 0: lineno += 1 #mark end of offending line pos = "0.0 + %d lines + %d chars" % (lineno-1, offset-1) diff --git a/Misc/ACKS b/Misc/ACKS index 45ab6a44fa7..a1edc77b2fe 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -705,6 +705,7 @@ Jean-François Piéronne Guilherme Polo Michael Pomraning Iustin Pop +Claudiu Popa John Popplewell Amrit Prem Paul Prescod diff --git a/Misc/NEWS b/Misc/NEWS index d52156d417c..5289c3799dd 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -25,6 +25,10 @@ Core and Builtins Library ------- +- Issue #9871: Prevent IDLE 3 crash when given byte stings + with invalid hex escape sequences, like b'\x0'. + (Original patch by Claudiu Popa.) + - Issue #8933: distutils' PKG-INFO files will now correctly report Metadata-Version: 1.1 instead of 1.0 if a Classifier or Download-URL field is present.