[ python-Bugs-1284496 ] traceback module can return undecodable byte strings

SourceForge.net noreply at sourceforge.net
Thu Sep 8 07:26:33 CEST 2005


Bugs item #1284496, was opened at 2005-09-08 15:26
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1284496&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Stuart Bishop (zenzen)
Assigned to: Nobody/Anonymous (nobody)
Summary: traceback module can return undecodable byte strings

Initial Comment:
The traceback module does not attempt to validate the
string representation of exceptions or enforce any
character set restrictions. It implements garbage in,
garbage out:

>>> import traceback
>>> try:
...     value = u'hello'.encode('utf16')
...     raise ValueError('Invalid value %s' % value)
... except:
...     traceback.format_exc()
...
'Traceback (most recent call last):\n  File "<stdin>",
line 2, in ?\nValueError: Invalid value
\xff\xfeh\x00e\x00l\x00l\x00o\x00\n'

So if an exception is raised that is not pure ASCII, we
end up with a traceback in an unknown encoding, and
possibly in no valid encoding at all.

This is problematic to applications which work with
Unicode strings internally, as when they try to report
the error they need to convert the traceback to ASCII
and they will get an encoding exception (non Unicode
applications tend to just spit out the byte stream and
let the user deal with it). Raising an exception that
resets your xterm's title is left as an excercise to
the reader ;)

Should the traceback module sanitize tracebacks it
returns, or is the burden on the application (eg. the
Python interactive interpreter, cgitb etc.) to sanitize
tracebacks using something like:

traceback = traceback.decode('ascii',
'replace').encode('ascii', 'backslashreplace')



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1284496&group_id=5470


More information about the Python-bugs-list mailing list