Merge pull request #10494 from fifthdegree/asn1_int_fix

Fix ASN.1 integer decoding
This commit is contained in:
David Fort 2024-08-21 22:46:37 +02:00 committed by GitHub
commit c7b519472b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1020,17 +1020,24 @@ static size_t WinPrAsn1DecReadIntegerLike(WinPrAsn1Decoder* dec, WinPrAsn1_tag e
size_t ret = readTagAndLen(dec, &dec->source, &tag, &len);
if (!ret || (tag != expectedTag))
return 0;
if (!Stream_CheckAndLogRequiredLength(TAG, &dec->source, len) || (len > 4))
if (len == 0 || !Stream_CheckAndLogRequiredLength(TAG, &dec->source, len) || (len > 4))
return 0;
WinPrAsn1_INTEGER val = 0;
for (size_t x = 0; x < len; x++)
UINT8 v = 0;
Stream_Read_UINT8(&dec->source, v);
if (v & 0x80)
val = 0xFFFFFFFF;
val |= v;
for (size_t x = 1; x < len; x++)
{
INT8 v = 0;
Stream_Read_INT8(&dec->source, v);
Stream_Read_UINT8(&dec->source, v);
val = (WinPrAsn1_INTEGER)(((UINT32)val) << 8);
val |= v;
}
*target = val;
ret += len;