Merge pull request #8634 from JacobBarthelmeh/pkcs7_stream

account for edge case with pkcs7 streaming
This commit is contained in:
David Garske
2025-04-07 16:01:14 -07:00
committed by GitHub

View File

@ -2635,7 +2635,14 @@ static int wc_PKCS7_EncodeContentStream(wc_PKCS7* pkcs7, ESD* esd, void* aes,
/* check and handle octet boundary */
sz = contentDataRead;
if ((int)idx + sz > BER_OCTET_LENGTH) {
int amtWritten = 0;
/* loop over current buffer until it is empty */
while (idx + (word32)sz > BER_OCTET_LENGTH) {
sz = BER_OCTET_LENGTH;
if (idx > 0) { /* account for previously stored data */
sz = BER_OCTET_LENGTH - (int)idx;
}
contentDataRead -= sz;
XMEMCPY(contentData + idx, buf, (word32)sz);
@ -2647,9 +2654,13 @@ static int wc_PKCS7_EncodeContentStream(wc_PKCS7* pkcs7, ESD* esd, void* aes,
XFREE(contentData, heap, DYNAMIC_TYPE_PKCS7);
return ret;
}
idx = 0; /* cleared out previously stored data */
amtWritten += sz;
sz = contentDataRead;
}
/* copy over any remaining data */
XMEMCPY(contentData, buf + sz, (word32)contentDataRead);
XMEMCPY(contentData, buf + amtWritten, (word32)contentDataRead);
idx = (word32)contentDataRead;
}
else {