b***@artifex.com
2017-11-05 18:30:40 UTC
http://bugs.ghostscript.com/show_bug.cgi?id=698722
Bug ID: 698722
Summary: Erroneous Range-Check causes wrong arithmetic results
Product: Ghostscript
Version: master
Hardware: PC
OS: Linux
Status: UNCONFIRMED
Severity: normal
Priority: P4
Component: General
Assignee: ghostpdl-***@artifex.com
Reporter: bg+***@nerilex.org
QA Contact: gs-***@ghostscript.com
Word Size: ---
Created attachment 14436
--> http://bugs.ghostscript.com/attachment.cgi?id=14436&action=edit
patch to fix this issue
The Problem:
9223372036854775808 2 mul =
results in:
-9223372036854775808
During multiplication (and likely other opertaions), the result is checked to
fit inside the integer range by constructs like:
double ab = (double)op[-1].value.intval * op->value.intval;
if (ab > (double)MAX_PS_INT) /* (double)0x7fffffffffffffff */
make_real(op - 1, ab);
else if (ab < (double)MIN_PS_INT) /* (double)(int64_t)0x8000000000000000 */
make_real(op - 1, ab);
else
op[-1].value.intval = (ps_int)ab;
Due to the behaviour of C casts, we may get:
MAX_PS_INT == 9223372036854775807
and
(double)MAX_PS_INT == 9223372036854775808
Using
(double)((ps_int)ab) == ab
as check may be more helpful.
Bug ID: 698722
Summary: Erroneous Range-Check causes wrong arithmetic results
Product: Ghostscript
Version: master
Hardware: PC
OS: Linux
Status: UNCONFIRMED
Severity: normal
Priority: P4
Component: General
Assignee: ghostpdl-***@artifex.com
Reporter: bg+***@nerilex.org
QA Contact: gs-***@ghostscript.com
Word Size: ---
Created attachment 14436
--> http://bugs.ghostscript.com/attachment.cgi?id=14436&action=edit
patch to fix this issue
The Problem:
9223372036854775808 2 mul =
results in:
-9223372036854775808
During multiplication (and likely other opertaions), the result is checked to
fit inside the integer range by constructs like:
double ab = (double)op[-1].value.intval * op->value.intval;
if (ab > (double)MAX_PS_INT) /* (double)0x7fffffffffffffff */
make_real(op - 1, ab);
else if (ab < (double)MIN_PS_INT) /* (double)(int64_t)0x8000000000000000 */
make_real(op - 1, ab);
else
op[-1].value.intval = (ps_int)ab;
Due to the behaviour of C casts, we may get:
MAX_PS_INT == 9223372036854775807
and
(double)MAX_PS_INT == 9223372036854775808
Using
(double)((ps_int)ab) == ab
as check may be more helpful.
--
You are receiving this mail because:
You are the QA Contact for the bug.
You are receiving this mail because:
You are the QA Contact for the bug.