Fix potential overflow in huffman decoding

This commit is contained in:
Jeffrey Pfau 2014-10-25 06:05:00 -07:00
parent 732e29e3c6
commit fe3f01a5ae
1 changed files with 1 additions and 1 deletions

View File

@ -319,7 +319,7 @@ static void _unHuffman(struct GBA* gba, uint32_t source, uint32_t* dest) {
while (remaining > 0) {
uint32_t bitstream = cpu->memory.load32(cpu, sPointer, 0);
sPointer += 4;
for (bitsRemaining = 32; bitsRemaining > 0; --bitsRemaining, bitstream <<= 1) {
for (bitsRemaining = 32; bitsRemaining > 0 && remaining > 0; --bitsRemaining, bitstream <<= 1) {
uint32_t next = (nPointer & ~1) + HuffmanNodeGetOffset(node) * 2 + 2;
if (bitstream & 0x80000000) {
// Go right