winicon: Fix potential integer overflow

This commit is contained in:
bakkeby 2021-11-20 22:48:46 +01:00
parent efb9cc721e
commit c7af5c6b67

View File

@ -73,13 +73,13 @@ geticonprop(Window win)
unsigned long *i; unsigned long *i;
uint32_t bstd = UINT32_MAX, d, m; uint32_t bstd = UINT32_MAX, d, m;
for (i = p; i < end - 1; i += sz) { for (i = p; i < end - 1; i += sz) {
if ((w = *i++) > UINT16_MAX || (h = *i++) > UINT16_MAX) { XFree(p); return NULL; } if ((w = *i++) >= 16384 || (h = *i++) >= 16384) { XFree(p); return NULL; }
if ((sz = w * h) > end - i) break; if ((sz = w * h) > end - i) break;
if ((m = w > h ? w : h) >= ICONSIZE && (d = m - ICONSIZE) < bstd) { bstd = d; bstp = i; } if ((m = w > h ? w : h) >= ICONSIZE && (d = m - ICONSIZE) < bstd) { bstd = d; bstp = i; }
} }
if (!bstp) { if (!bstp) {
for (i = p; i < end - 1; i += sz) { for (i = p; i < end - 1; i += sz) {
if ((w = *i++) > UINT16_MAX || (h = *i++) > UINT16_MAX) { XFree(p); return NULL; } if ((w = *i++) >= 16384 || (h = *i++) >= 16384) { XFree(p); return NULL; }
if ((sz = w * h) > end - i) break; if ((sz = w * h) > end - i) break;
if ((d = ICONSIZE - (w > h ? w : h)) < bstd) { bstd = d; bstp = i; } if ((d = ICONSIZE - (w > h ? w : h)) < bstd) { bstd = d; bstp = i; }
} }