[Patches] [ python-Patches-1309009 ] pyexpat.c: Two line fix for decoding crash
SourceForge.net
noreply at sourceforge.net
Fri Sep 30 02:25:34 CEST 2005
Patches item #1309009, was opened at 2005-09-29 18:46
Message generated for change (Comment added) made by vulturex
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1309009&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: Evan Jones (vulturex)
Assigned to: Nobody/Anonymous (nobody)
Summary: pyexpat.c: Two line fix for decoding crash
Initial Comment:
The attached Python script "test.py" will crash Python version 2.3,
2.4 and current CVS. The problem is that expat could pass back a
string that is not in UTF8 format when the character encoding is not
specified. In the example "test.py" the XML document is in latin_1
format, but Python thinks it is in UTF-8 format.
The workaround is to decode the string into Unicode first, then
encode it as UTF8. However, if this data was coming from a file or a
user, it could crash the interpreter.
With the attached patch, instead of causing a segmentation fault it
raises an exception, which is exactly what Python 2.2 does in this
case:
Traceback (most recent call last):
File "/home/ejones/test.py", line 5, in ?
dom = xml.dom.minidom.parseString( x.encode( 'latin_1' ) )
File "/home/ejones/python/dist/src/Lib/xml/dom/minidom.py", line
1925, in parseString
return expatbuilder.parseString(string)
File "/home/ejones/python/dist/src/Lib/xml/dom/expatbuilder.py",
line 940, in parseString
return builder.parseString(string)
File "/home/ejones/python/dist/src/Lib/xml/dom/expatbuilder.py",
line 223, in parseString
parser.Parse(string, True)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 4-6:
invalid data
----------------------------------------------------------------------
>Comment By: Evan Jones (vulturex)
Date: 2005-09-29 20:25
Message:
Logged In: YES
user_id=539295
I've also attached a patch which adds this as a test case to
test_minidom.py.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1309009&group_id=5470
More information about the Patches
mailing list