crypt32: Grow item size buffer by more than 1 at a time.

When Steam starts and connects, it sometimes does some crypt32
processing and ends up spending a huge amount of time in ntdll memcpy,
reallocating buffers, effectively getting stuck while connecting to the
user account.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-07-02 12:18:22 +02:00 committed by Alexandre Julliard
parent 0c36633a20
commit 8b8b43d5f3

View file

@ -628,7 +628,7 @@ static BOOL CRYPT_AsnDecodeArray(const struct AsnArrayDescriptor *arrayDesc,
if ((ret = CRYPT_GetLengthIndefinite(pbEncoded, cbEncoded, &dataLen)))
{
DWORD bytesNeeded = arrayDesc->minArraySize, cItems = 0, decoded;
DWORD bytesNeeded = arrayDesc->minArraySize, cItems = 0, capacity = 0, decoded;
BYTE lenBytes = GET_LEN_BYTES(pbEncoded[1]);
/* There can be arbitrarily many items, but there is often only one.
*/
@ -687,17 +687,18 @@ static BOOL CRYPT_AsnDecodeArray(const struct AsnArrayDescriptor *arrayDesc,
continue;
}
cItems++;
if (itemSizes != &itemSize)
itemSizes = CryptMemRealloc(itemSizes,
cItems * sizeof(struct AsnArrayItemSize));
else if (cItems > 1)
if (++cItems <= 1)
itemSizes = &itemSize;
else if (itemSizes == &itemSize)
{
itemSizes =
CryptMemAlloc(
cItems * sizeof(struct AsnArrayItemSize));
if (itemSizes)
*itemSizes = itemSize;
capacity = 1024;
itemSizes = CryptMemAlloc(capacity * sizeof(struct AsnArrayItemSize));
if (itemSizes) *itemSizes = itemSize;
}
else if (cItems > capacity)
{
capacity = capacity * 3 / 2;
itemSizes = CryptMemRealloc(itemSizes, capacity * sizeof(struct AsnArrayItemSize));
}
if (itemSizes)
{