1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Fix overflow on numeric comparison (#2849)

Although #2839 fixed the overflow of exponent subtraction,
there still is possibility of overflow in the `D2U` macro.
This patch fixes the overflow in the `D2U` macro, and also
truncates the maximum digits to `DEC_MAX_DIGITS`.
This commit is contained in:
itchyny
2023-08-17 15:56:57 +09:00
committed by GitHub
parent 0733fd3d58
commit 7d64381016
2 changed files with 4 additions and 2 deletions

View File

@@ -528,7 +528,9 @@ static decContext* tsd_dec_ctx_get(pthread_key_t *key) {
if (key == &dec_ctx_key)
{
decContextDefault(ctx, DEC_INIT_BASE);
ctx->digits = INT32_MAX - (ctx->emax - ctx->emin - 1);
// make sure (Int)D2U(rhs->exponent-lhs->exponent) does not overflow
ctx->digits = MIN(DEC_MAX_DIGITS,
INT32_MAX - (DECDPUN - 1) - (ctx->emax - ctx->emin - 1));
ctx->traps = 0; /*no errors*/
}
else if (key == &dec_ctx_dbl_key)

View File

@@ -569,7 +569,7 @@ true
true
# #2825
(1e999999999, 10e999999999) > (1e-1147483648, 0.1e-1147483648)
(1e999999999, 10e999999999) > (1e-1147483646, 0.1e-1147483646)
null
true
true