Repository navigation
Conversation
we do the same calculation in advance as mpz_realloc overflow check to avoid abort.
|
Well, what can I say … a library should never ever call |
| gmp_init_random(); | ||
|
|
||
| mpz_urandomb(gmpnum_result, GMPG(rand_state), bits); | ||
| mpz_urandomb(gmpnum_result, GMPG(rand_state), (mp_bitcnt_t)bits); |
There was a problem hiding this comment.
It s just to avoid pedantic build warning I guess, bits being always > 0 and < max value for unsigned long int ; I think it is fine.
There was a problem hiding this comment.
Well, just extraneous; I'd remove it (could still trigger some compiler/analyser diagnostic without the cast).
There was a problem hiding this comment.
Ah, I overlooked your comment. Let's leave it as is.
| #if SIZEOF_SIZE_T == 4 | ||
| const zend_long maxbits = ULONG_MAX / GMP_NUMB_BITS; | ||
| #else | ||
| const zend_long maxbits = INT_MAX; |
There was a problem hiding this comment.
This still can overflow. libgmp does this check, but afterwards calculates ((new_alloc) * sizeof (mp_limb_t)), where sizeof(mp_limb_t) is certainly larger than 2 (I assume it's usually four or eight).
There was a problem hiding this comment.
Disregard. This is fine; I was confused by 32bit using ULONG_MAX, but 64bit using INT_MAX. The 32bit case looks fishy (for LP64), though.
Seems a particular use case generalised (or internal state going to be compromised if it keeps going ? no idea), I wish there were a runtime setting to at least being able to choose what to do |
we do the same calculation in advance as mpz_realloc overflow check to avoid abort.