classification
Title: warnings.warn segfaults on bad formatted string
Type: crash Stage: resolved
Components: Interpreter Core Versions: Python 3.1, Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ocean-city Nosy List: brett.cannon, jcsalterego, ocean-city, r.david.murray, wiesenth
Priority: release blocker Keywords: patch

Created on 2009-07-04 10:14 by wiesenth, last changed 2009-07-19 13:09 by r.david.murray. This issue is now closed.

Files
File name Uploaded Description Edit
warnsegfault.py wiesenth, 2009-07-04 10:14 Crash in 2.6 and 3.0 in warnings.warn
warnings_segfault.patch ocean-city, 2009-07-04 12:59
test_warnings.diff brett.cannon, 2009-07-17 05:58 Test for bus error trigger
unnamed brett.cannon, 2009-07-17 17:20
Messages (8)
msg90111 - (view) Author: (wiesenth) Date: 2009-07-04 10:14
The interpreter crashes with an segmentation fault when warnings.warn
shall output a Warning instance, whose string representation is bad
formatted.

Don't know if this is fixed in a minor 2.6 release or in 2.7, I use the
Ubuntu 9.04 python2.6 package.

An easy reproducing example is given.

This is also an issue within python3.0 (python3.1 does not exist in the
repositories)
msg90116 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2009-07-04 12:59
I hope attached patch will fix this issue.
msg90122 - (view) Author: Jerry Chen (jcsalterego) Date: 2009-07-04 17:23
Bug and patch confirmed on both py3k and python2.7 branches

Before:

$ ./python.exe warnsegfault.py 
this exception is caught: incomplete format
this exception is also caught: incomplete format
Bus error

After:

$ ./python.exe warnsegfault.py this exception is caught: incomplete format
this exception is also caught: incomplete format
Traceback (most recent call last):
  File "warnsegfault.py", line 21, in <module>
    warnings.warn(MyWarning())
  File "warnsegfault.py", line 10, in __str__
    return "A bad formatted string %(err)" % {"err" : "there is no %(err)s"}
ValueError: incomplete format
msg90605 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2009-07-17 05:58
Here is a patch for test_warning to test for the failure. Hirokazu, since 
you found the fix, do you want to do the commit, or do you want me to 
handle it since this will need to be applied to all active branches?
msg90606 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2009-07-17 07:03
I've committed in r74040(trunk), r74043(release26-maint), r74046(py3k), 
r74047(release31-maint). Is release30-maint still active?
msg90630 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2009-07-17 17:20
On Fri, Jul 17, 2009 at 00:03, Hirokazu Yamamoto <report@bugs.python.org>wrote:

>
> Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> added the comment:
>
> I've committed in r74040(trunk), r74043(release26-maint), r74046(py3k),
> r74047(release31-maint). Is release30-maint still active?
>

No, 3.0 is dead.

Thanks, Hirokazu!
msg90692 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-07-18 21:34
The backport to 2.6 needs adjustment.  The test fails:

Traceback (most recent call last):
  File
"/home/rdmurray/python/release26-maint/Lib/test/test_warnings.py", line
350, in test_bad_str
    with self.assertRaises(ValueError):
TypeError: failUnlessRaises() takes at least 3 arguments (2 given)

assertRaises can't be used as a context manager in 2.6.
msg90704 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2009-07-19 03:41
Thank you, I've fixed it in r74091. I should have checked test results 
on all branches.
History
Date User Action Args
2009-07-19 13:09:22r.david.murraysetstatus: open -> closed
2009-07-19 03:41:53ocean-citysetmessages: + msg90704
2009-07-18 21:34:06r.david.murraysetstatus: closed -> open
nosy: + r.david.murray
messages: + msg90692

2009-07-17 17:20:25brett.cannonsetfiles: + unnamed

messages: + msg90630
2009-07-17 07:03:22ocean-citysetstatus: open -> closed
versions: + Python 3.1, Python 2.7, Python 3.2, - Python 3.0
messages: + msg90606

resolution: fixed
stage: commit review -> resolved
2009-07-17 05:58:58brett.cannonsetfiles: + test_warnings.diff
assignee: brett.cannon -> ocean-city
messages: + msg90605

stage: patch review -> commit review
2009-07-17 05:22:44brett.cannonsetpriority: release blocker
components: + Interpreter Core
stage: patch review
2009-07-04 17:23:24jcsalteregosetnosy: + jcsalterego
messages: + msg90122
2009-07-04 13:33:22benjamin.petersonsetassignee: brett.cannon

nosy: + brett.cannon
2009-07-04 12:59:18ocean-citysetfiles: + warnings_segfault.patch

nosy: + ocean-city
messages: + msg90116

keywords: + patch
2009-07-04 10:14:02wiesenthcreate