[Gmp-commit] /var/hg/gmp-6.2: mpz/inp_raw.c: Avoid bit size overflows

mercurial at gmplib.org mercurial at gmplib.org
Thu Oct 21 17:06:58 UTC 2021


details:   /var/hg/gmp-6.2/rev/561a9c25298e
changeset: 18135:561a9c25298e
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Oct 21 19:06:49 2021 +0200
description:
mpz/inp_raw.c: Avoid bit size overflows

diffstat:

 mpz/inp_raw.c |  5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diffs (16 lines):

diff -r e1fd9db13b47 -r 561a9c25298e mpz/inp_raw.c
--- a/mpz/inp_raw.c	Tue Dec 22 23:49:51 2020 +0100
+++ b/mpz/inp_raw.c	Thu Oct 21 19:06:49 2021 +0200
@@ -88,8 +88,11 @@
 
   abs_csize = ABS (csize);
 
+  if (UNLIKELY (abs_csize > ~(mp_bitcnt_t) 0 / 8))
+    return 0; /* Bit size overflows */
+
   /* round up to a multiple of limbs */
-  abs_xsize = BITS_TO_LIMBS (abs_csize*8);
+  abs_xsize = BITS_TO_LIMBS ((mp_bitcnt_t) abs_csize * 8);
 
   if (abs_xsize != 0)
     {


More information about the gmp-commit mailing list