Turo Lamminen
2015-04-30 8b0fae2ce1f9386f356af2b8c84571decfe613ab

Check the file contains enough data if the header claims it does

Found with AFL

1 files modified
18 ■■■■■ changed files
mojodds.c 18 ●●●●● patch | view | raw | blame | history
mojodds.c
@@ -314,6 +314,24 @@
            ht >>= 1;
        }
    }
    else if (*_textureType == MOJODDS_TEXTURE_2D)
    {
        // check that file contains enough data like the header says
        // TODO: also do this for other texture types
        uint32 wd = header->dwWidth;
        uint32 ht = header->dwHeight;
        uint32 dataLen = 0;
        for (i = 0; i < (int)*_miplevels; i++)
        {
            dataLen += MAX((wd + blockDim - 1) / blockDim, 1) * MAX((ht + blockDim - 1) / blockDim, 1) * blockSize;
            wd >>= 1;
            ht >>= 1;
        }
        if (*len < dataLen) {
            return 0;
        }
    }
    return 1;
} // parse_dds