classification
Title: crashes when comparing between a Decimal object and a bad Rational object
Type: crash Stage: resolved
Components: Extension Modules Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Oren Milman, serhiy.storchaka, skrah
Priority: normal Keywords: patch

Created on 2017-09-10 13:25 by Oren Milman, last changed 2017-09-10 17:07 by skrah. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3476 closed Oren Milman, 2017-09-10 15:01
PR 3477 merged skrah, 2017-09-10 15:18
PR 3479 merged python-dev, 2017-09-10 16:22
Messages (4)
msg301809 - (view) Author: Oren Milman (Oren Milman) * Date: 2017-09-10 13:25
The following code crashes the interpreter:

import decimal
import fractions

class BadRational(fractions.Fraction):
    numerator = None
    denominator = 42

decimal.Decimal() < BadRational()


this is because numerator_as_decimal() (in Modules/_decimal/_decimal.c) assumes
that 'numerator' is an integer.

multiply_by_denominator() (in Modules/_decimal/_decimal.c) also assumes that
'denominator' is an integer, and so the following code crashes the interpreter:

import decimal
import fractions

class BadRational(fractions.Fraction):
    numerator = 42
    denominator = None

decimal.Decimal() < BadRational()
msg301813 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2017-09-10 16:08
New changeset 3cedf46cdbeefc019f4a672c1104f3d5e94712bd by Stefan Krah in branch 'master':
bpo-31406: Fix crash due to lack of type checking in subclassing. (#3477)
https://github.com/python/cpython/commit/3cedf46cdbeefc019f4a672c1104f3d5e94712bd
msg301815 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2017-09-10 16:46
New changeset f8909d0e4b652256e4da153fa6be664490f60a07 by Stefan Krah (Miss Islington (bot)) in branch '3.6':
[3.6] bpo-31406: Fix crash due to lack of type checking in subclassing. (GH-3477) (#3479)
https://github.com/python/cpython/commit/f8909d0e4b652256e4da153fa6be664490f60a07
msg301817 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2017-09-10 17:07
Thanks for the report and the patch!
History
Date User Action Args
2017-09-10 17:07:20skrahsetstatus: open -> closed
stage: patch review -> resolved
2017-09-10 17:07:12skrahsetresolution: fixed
messages: + msg301817
versions: + Python 3.6
2017-09-10 16:46:52skrahsetmessages: + msg301815
2017-09-10 16:22:07python-devsetpull_requests: + pull_request3469
2017-09-10 16:08:06skrahsetmessages: + msg301813
2017-09-10 15:18:08skrahsetpull_requests: + pull_request3468
2017-09-10 15:01:53Oren Milmansetkeywords: + patch
stage: patch review
pull_requests: + pull_request3467
2017-09-10 13:47:18serhiy.storchakasetnosy: + skrah, serhiy.storchaka
2017-09-10 13:25:42Oren Milmancreate