[New-bugs-announce] [issue31406] crashes when comparing between a Decimal object and a bad Rational object

Oren Milman report at bugs.python.org
Sun Sep 10 09:25:42 EDT 2017


New submission from Oren Milman:

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()

----------
components: Extension Modules
messages: 301809
nosy: Oren Milman
priority: normal
severity: normal
status: open
title: crashes when comparing between a Decimal object and a bad Rational object
type: crash
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31406>
_______________________________________


More information about the New-bugs-announce mailing list