diff options
author | Stefan Krah <skrah@bytereef.org> | 2012-08-22 17:11:50 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2012-08-22 17:11:50 (GMT) |
commit | ad5b43995e758c7a1f81ce6cf2cd798b48712808 (patch) | |
tree | 807a78b4da935f606bfa066dde471a210a64a81a /Modules/_decimal/_decimal.c | |
parent | 2fd502f6a183fde7d8b4847d27e09884bf8006c7 (diff) | |
download | cpython-ad5b43995e758c7a1f81ce6cf2cd798b48712808.zip cpython-ad5b43995e758c7a1f81ce6cf2cd798b48712808.tar.gz cpython-ad5b43995e758c7a1f81ce6cf2cd798b48712808.tar.bz2 |
In the 32-bit build, dec_hash() raised InvalidOperation if the operand
had a coefficient with MAX_PREC=425000000 digits and a negative exponent.
Increasing the context limits above the official values fixes the issue
and is safe (in this case!).
Diffstat (limited to 'Modules/_decimal/_decimal.c')
-rw-r--r-- | Modules/_decimal/_decimal.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index ad84d58..6217a3f 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -4338,6 +4338,11 @@ _dec_hash(PyDecObject *v) } tmp->exp = 0; mpd_set_positive(tmp); + + maxctx.prec = MPD_MAX_PREC + 21; + maxctx.emax = MPD_MAX_EMAX + 21; + maxctx.emin = MPD_MIN_EMIN - 21; + mpd_qmul(tmp, tmp, exp_hash, &maxctx, &status); mpd_qrem(tmp, tmp, &p, &maxctx, &status); @@ -4346,11 +4351,14 @@ _dec_hash(PyDecObject *v) result = (result == -1) ? -2 : result; if (status != 0) { - status |= MPD_Invalid_operation; - if (dec_addstatus(context, status)) { - result = -1; - goto finish; + if (status & MPD_Malloc_error) { + goto malloc_error; + } + else { + PyErr_SetString(PyExc_RuntimeError, + "dec_hash: internal error: please report"); } + result = -1; } |