Fix for mp_radix_size with radix 2 and mp_int equal to zero. Fix applies to normal and fast math only. ZD11419.

This commit is contained in:
David Garske
2020-12-21 12:41:32 -08:00
parent b4111e2f65
commit 53e79f1053
2 changed files with 9 additions and 3 deletions

View File

@ -5256,7 +5256,10 @@ int mp_radix_size (mp_int *a, int radix, int *size)
/* special case for binary */
if (radix == MP_RADIX_BIN) {
*size = mp_count_bits (a) + (a->sign == MP_NEG ? 1 : 0) + 1;
*size = mp_count_bits(a);
if (*size == 0)
*size = 1;
*size += (a->sign == MP_NEG ? 1 : 0) + 1; /* "-" sign + null term */
return MP_OKAY;
}

View File

@ -5550,8 +5550,11 @@ int mp_radix_size (mp_int *a, int radix, int *size)
/* special case for binary */
if (radix == 2) {
*size = fp_count_bits (a) + (a->sign == FP_NEG ? 1 : 0) + 1;
return FP_YES;
*size = fp_count_bits(a);
if (*size == 0)
*size = 1;
*size += (a->sign == FP_NEG ? 1 : 0) + 1; /* "-" sign + null term */
return FP_OKAY;
}
/* make sure the radix is in range */