From 002c76edb06d432fe6a5b24aff7dc8133d5d02d1 Mon Sep 17 00:00:00 2001
From: Turo Lamminen <turotl@gmail.com>
Date: Sat, 09 May 2015 14:54:16 +0000
Subject: [PATCH] Improve invalid miplevels calculation to too many mips relative to size
---
mojodds.c | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/mojodds.c b/mojodds.c
index ffbed55..524bca6 100644
--- a/mojodds.c
+++ b/mojodds.c
@@ -214,17 +214,17 @@
*_miplevels = (header->dwCaps & DDSCAPS_MIPMAP) ? header->dwMipMapCount : 1;
unsigned int calculatedMipLevels = uintLog2(MAX(width, height)) + 1;
- if (*_miplevels > 32)
- {
- // too many mip levels, width and height would be larger than 32-bit int
- // file is corrupted
- return 0;
- }
- else if (*_miplevels == 0)
+ if (*_miplevels == 0)
{
// invalid, calculate it ourselves from size
*_miplevels = calculatedMipLevels;
}
+ else if (*_miplevels > calculatedMipLevels)
+ {
+ // too many mip levels, several would be 1x1
+ // file is corrupted
+ return 0;
+ }
if (header->ddspf.dwFlags & DDPF_FOURCC)
{
--
Gitblit v1.9.3