Language: C
Label: safe
CWE: CWE-120 \u2014 Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow.

Code:
static int ncrush_generate_tables(NCRUSH_CONTEXT* context)
{
	UINT32 k, i;
	int j, l;
	k = 0;

	WINPR_ASSERT(context);
	WINPR_ASSERT(28 < ARRAYSIZE(LOMBitsLUT));

	for (i = 0; i < 28; i++)
	{
		for (j = 0; j < 1 << LOMBitsLUT[i]; j++)
		{
			l = (k++) + 2;
			context->HuffTableLOM[l] = (int)i;
		}
	}

	for (k = 2; k < 4096; k++)
	{
		if ((k - 2) >= 768)
			i = 28;
		else
			i = context->HuffTableLOM[k];

		if (i >= ARRAYSIZE(LOMBitsLUT))
			return -1;
		if (i >= ARRAYSIZE(LOMBaseLUT))
			return -1;

		if (((((1 << LOMBitsLUT[i]) - 1) & (k - 2)) + LOMBaseLUT[i]) != k)
			return -1;
	}

	k = 0;

	for (i = 0; i < 16; i++)
	{
		for (j = 0; j < 1 << CopyOffsetBitsLUT[i]; j++)
		{
			l = k++ + 2;
			context->HuffTableCopyOffset[l] = i;
		}
	}

	k /= 128;

	for (i = 16; i < 32; i++)
	{
		for (j = 0; j < 1 << (CopyOffsetBitsLUT[i] - 7); j++)
		{
			l = k++ + 2 + 256;
			context->HuffTableCopyOffset[l] = i;
		}
	}

	if ((k + 256) > 1024)
		return -1;

	return 1;
}