@@ -106,6 +106,7 @@ struct PKCS7State {
106106 word32 currContSz; /* size of current content */
107107 word32 currContRmnSz; /* remaining size of current content */
108108 word32 accumContSz; /* size of accumulated content size */
109+ int recipientSz; /* size of recipient set */
109110 byte tmpIv[MAX_CONTENT_IV_SIZE]; /* store IV if needed */
110111#ifdef WC_PKCS7_STREAM_DEBUG
111112 word32 peakUsed; /* most bytes used for struct at any one time */
@@ -12460,14 +12461,16 @@ int wc_PKCS7_DecodeEnvelopedData(wc_PKCS7* pkcs7, byte* in,
1246012461 #ifndef NO_PKCS7_STREAM
1246112462 tmpIdx = idx;
1246212463 pkcs7->stream->aad = decryptedKey;
12464+ pkcs7->stream->expected = (word32)ret; /* get the full recipient set */
12465+ pkcs7->stream->recipientSz = ret;
1246312466 #endif
1246412467 FALL_THROUGH;
1246512468
1246612469 case WC_PKCS7_ENV_2:
1246712470 #ifndef NO_PKCS7_STREAM
1246812471 /* store up enough buffer for initial info set decode */
12469- if ((ret = wc_PKCS7_AddDataToStream(pkcs7, in, inSz, MAX_LENGTH_SZ +
12470- MAX_VERSION_SZ + ASN_TAG_SZ , &pkiMsg, &idx)) != 0) {
12472+ if ((ret = wc_PKCS7_AddDataToStream(pkcs7, in, inSz,
12473+ pkcs7->stream->expected , &pkiMsg, &idx)) != 0) {
1247112474 return ret;
1247212475 }
1247312476 #endif
@@ -12483,6 +12486,7 @@ int wc_PKCS7_DecodeEnvelopedData(wc_PKCS7* pkcs7, byte* in,
1248312486 #ifndef NO_PKCS7_STREAM
1248412487 decryptedKey = pkcs7->stream->aad;
1248512488 decryptedKeySz = MAX_ENCRYPTED_KEY_SZ;
12489+ tmpIdx = idx;
1248612490 #endif
1248712491
1248812492 ret = wc_PKCS7_DecryptRecipientInfos(pkcs7, in, inSz, &idx,
@@ -12497,6 +12501,14 @@ int wc_PKCS7_DecodeEnvelopedData(wc_PKCS7* pkcs7, byte* in,
1249712501 if (ret != 0)
1249812502 break;
1249912503 #ifndef NO_PKCS7_STREAM
12504+ /* advance idx past recipient info set */
12505+ idx = tmpIdx + (word32)pkcs7->stream->recipientSz;
12506+
12507+ /* process aditional recipients as read */
12508+ if ((ret = wc_PKCS7_StreamEndCase(pkcs7, &tmpIdx, &idx)) != 0) {
12509+ break;
12510+ }
12511+
1250012512 tmpIdx = idx;
1250112513 pkcs7->stream->aadSz = decryptedKeySz;
1250212514 pkcs7->stream->expected = MAX_LENGTH_SZ + MAX_VERSION_SZ +
0 commit comments