Merge pull request #5969 from SparkiDev/sp_int_to_bin_len

SP int: fail when buffer writing to is too small for number
This commit is contained in:
David Garske
2023-01-12 13:44:39 -08:00
committed by GitHub

View File

@ -16878,11 +16878,16 @@ int sp_to_unsigned_bin_len(const sp_int* a, byte* out, int outSz)
/* Put each digit in. */
for (i = 0; (j >= 0) && (i < a->used); i++) {
int b;
sp_int_digit d = a->dp[i];
/* Place each byte of a digit into the buffer. */
for (b = 0; b < SP_WORD_SIZE; b += 8) {
out[j--] = (byte)(a->dp[i] >> b);
out[j--] = (byte)d;
d >>= 8;
/* Stop if the output buffer is filled. */
if (j < 0) {
if ((i < a->used - 1) || (d > 0)) {
err = BUFFER_E;
}
break;
}
}