Skip to content
Myr

Fix signed integer overflow undefined behaviour in decNumber.c

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60691 $ ./jq <<< 0E2202012202 src/decNumber/decNumber.c:598:18: runtime error: signed integer overflow: 440402440 + 1761609760 cannot be represented in type 'int' 0E+999999999 Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60683 $ ./jq <<< 5E7657765755 src/decNumber/decNumber.c:598:18: runtime error: left shift of 765776575 by 3 places cannot be represented in type 'int' src/decNumber/decNumber.c:598:18: runtime error: signed integer overflow: 1531553150 + 1831245304 cannot be represented in type 'int' 1.7976931348623157e+308

authored by Emanuele Torre · committed by Nico Williams · parent 15fd31d · Browse files · 1 file+4 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+4 added−2 removed

  • other:+4 added−2 removed

1 file+4 added−2 removed

modified:src/decNumber/decNumber.c+4 added-2 removed
580 unmodified lines
581 // had some digits; exponent is only valid sequence now582 Flag nege; // 1=negative exponent583 const char *firstexp; // -> first significant exponent digit584 status=DEC_Conversion_syntax;// assume the worst585 uInt expa=0; // accumulator for exponent586 if (*c!='e' && *c!='E') break;587 /* Found 'e' or 'E' -- now process explicit exponent */588 // 1998.07.11: sign no longer required589 nege=0;
5 unmodified lines
595 for (; *c=='0' && *(c+1)!='\0';) c++; // strip insignificant zeros596 firstexp=c; // save exponent digit place597 for (; ;c++) {598 if (*c<'0' || *c>'9') break; // not a digit598 exponent=X10(exponent)+(Int)*c-(Int)'0';599 expa=X10(expa)+(Int)*c-(Int)'0';600 } // c601 // if not now on a '\0', *c must not be a digit602 if (*c!='\0') break;603604 // (this next test must be after the syntax checks)605 // if it was too long the exponent may have wrapped, so check606 // carefully and set it to a certain overflow if wrap possible607 if (c>=firstexp+9+1) {607 if (c>firstexp+9+1 || *firstexp>'1') exponent=DECNUMMAXE*2;608 if (c>firstexp+9+1 || *firstexp>'1') expa=DECNUMMAXE*2;609 // [up to 1999999999 is OK, for example 1E-1000000998]610 }611 exponent=(Int)expa; // save exponent612 if (nege) exponent=-exponent; // was negative613 status=0; // is OK614 } // stuff after digits615
7528 unmodified lines