Be safer with uneven lengths

This commit is contained in:
Matt Nadareski
2023-01-03 00:14:42 -08:00
parent c28de855e2
commit eefc52d1dd

View File

@@ -356,7 +356,10 @@ namespace BurnOutSharp.Compression.Quantum
if (bitsleft > 16)
return;
bitbuf |= (uint)(((inbuf[inpos + 0] << 8) | inbuf[inpos + 1]) << (16 - bitsleft));
byte b0 = inpos + 0 < inbuf.Length ? inbuf[inpos + 0] : (byte)0;
byte b1 = inpos + 1 < inbuf.Length ? inbuf[inpos + 1] : (byte)0;
bitbuf |= (uint)(((b0 << 8) | b1) << (16 - bitsleft));
bitsleft += 16;
inpos += 2;
}