Changelog: Validate imagelists with christmas magic.
Index: dlls/comctl32/imagelist.h =================================================================== RCS file: /home/wine/wine/dlls/comctl32/imagelist.h,v retrieving revision 1.3 diff -u -r1.3 imagelist.h --- dlls/comctl32/imagelist.h 31 May 2002 23:25:44 -0000 1.3 +++ dlls/comctl32/imagelist.h 24 Dec 2002 19:26:09 -0000 @@ -53,6 +53,8 @@ INT nOvlIdx[15]; }; +#define IMAGELIST_MAGIC 0x4C4D4948 + /* Header used by ImageList_Read() and ImageList_Write() */ typedef struct _ILHEAD { Index: dlls/comctl32/imagelist.c =================================================================== RCS file: /home/wine/wine/dlls/comctl32/imagelist.c,v retrieving revision 1.68 diff -u -r1.68 imagelist.c --- dlls/comctl32/imagelist.c 5 Dec 2002 20:33:09 -0000 1.68 +++ dlls/comctl32/imagelist.c 24 Dec 2002 19:26:11 -0000 @@ -171,7 +171,7 @@ HBITMAP hOldBitmapImage, hOldBitmap; TRACE("himl=%p hbmimage=%p hbmmask=%p\n", himl, hbmImage, hbmMask); - if (!himl || !hbmImage) + if (!himl || himl->magic!=IMAGELIST_MAGIC || !hbmImage) return -1; GetObjectA (hbmImage, sizeof(BITMAP), (LPVOID)&bmp); @@ -283,7 +283,7 @@ COLORREF bkColor; TRACE("himl=%p hbitmap=%p clrmask=%lx\n", himl, hBitmap, clrMask); - if (himl == NULL) + if (himl == NULL || himl->magic!=IMAGELIST_MAGIC) return -1; if (!GetObjectA (hBitmap, sizeof(BITMAP), &bmp)) @@ -599,6 +599,7 @@ if (!himl) return NULL; + himl->magic = IMAGELIST_MAGIC; himl->cx = cx; himl->cy = cy; himl->flags = flags; @@ -625,6 +626,7 @@ 1, himl->uBitsPixel, NULL); if (himl->hbmImage == 0) { ERR("Error creating image bitmap!\n"); + ImageList_Destroy(himl); return NULL; } } @@ -640,8 +642,7 @@ 1, 1, NULL); if (himl->hbmMask == 0) { ERR("Error creating mask bitmap!\n"); - if (himl->hbmImage) - DeleteObject (himl->hbmImage); + ImageList_Destroy(himl); return NULL; } } @@ -678,7 +679,7 @@ BOOL WINAPI ImageList_Destroy (HIMAGELIST himl) { - if (!himl) + if (!himl || himl->magic!=IMAGELIST_MAGIC) return FALSE; /* delete image bitmaps */ @@ -1248,7 +1249,7 @@ HIMAGELIST himlDst; HDC hdcSrc, hdcDst; - if (himlSrc == NULL) { + if (himlSrc == NULL || himlSrc->magic!=IMAGELIST_MAGIC) { ERR("Invalid image list handle!\n"); return NULL; } @@ -1407,7 +1408,7 @@ HBITMAP hOldDstBitmap; HDC hdcDst; - if ((himl == NULL) || (i < 0) || (i >= himl->cCurImage)) return 0; + if ((himl == NULL) || himl->magic!=IMAGELIST_MAGIC || (i < 0) || (i >= himl->cCurImage)) return 0; hdcDst = CreateCompatibleDC(0); @@ -1461,7 +1462,7 @@ BOOL WINAPI ImageList_GetIconSize (HIMAGELIST himl, INT *cx, INT *cy) { - if (himl == NULL) + if (himl == NULL || himl->magic!=IMAGELIST_MAGIC) return FALSE; if ((himl->cx <= 0) || (himl->cy <= 0)) return FALSE; @@ -1491,7 +1492,7 @@ INT WINAPI ImageList_GetImageCount (HIMAGELIST himl) { - if (himl == NULL) + if (himl == NULL || himl->magic!=IMAGELIST_MAGIC) return 0; return himl->cCurImage; @@ -1516,7 +1517,7 @@ BOOL WINAPI ImageList_GetImageInfo (HIMAGELIST himl, INT i, IMAGEINFO *pImageInfo) { - if ((himl == NULL) || (pImageInfo == NULL)) + if ((himl == NULL) || himl->magic!=IMAGELIST_MAGIC || (pImageInfo == NULL)) return FALSE; if ((i < 0) || (i >= himl->cCurImage)) return FALSE; @@ -1554,7 +1555,7 @@ BOOL WINAPI ImageList_GetImageRect (HIMAGELIST himl, INT i, LPRECT lpRect) { - if ((himl == NULL) || (lpRect == NULL)) + if ((himl == NULL) || himl->magic!=IMAGELIST_MAGIC || (lpRect == NULL)) return FALSE; if ((i < 0) || (i >= himl->cCurImage)) return FALSE; @@ -1625,6 +1626,10 @@ himl = ImageList_Create (cx, bmp.bmHeight, ILC_MASK | ILC_COLOR, nImageCount, cGrow); + if (!himl) { + DeleteObject (handle); + return NULL; + } ImageList_AddMasked (himl, (HBITMAP)handle, clrMask); } else if ((uType == IMAGE_ICON) || (uType == IMAGE_CURSOR)) { @@ -1635,6 +1640,12 @@ GetObjectA (ii.hbmColor, sizeof(BITMAP), (LPVOID)&bmp); himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight, ILC_MASK | ILC_COLOR, 1, cGrow); + if (!himl) { + DeleteObject (ii.hbmColor); + DeleteObject (ii.hbmMask); + DeleteObject (handle); + return NULL; + } ImageList_Add (himl, ii.hbmColor, ii.hbmMask); DeleteObject (ii.hbmColor); DeleteObject (ii.hbmMask); @@ -1702,6 +1713,10 @@ himl = ImageList_Create (cx, bmp.bmHeight, ILC_MASK | ILC_COLOR, nImageCount, cGrow); + if (!himl) { + DeleteObject (handle); + return NULL; + } ImageList_AddMasked (himl, (HBITMAP)handle, clrMask); } else if ((uType == IMAGE_ICON) || (uType == IMAGE_CURSOR)) { @@ -1712,6 +1727,12 @@ GetObjectA (ii.hbmMask, sizeof(BITMAP), (LPVOID)&bmp); himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight, ILC_MASK | ILC_COLOR, 1, cGrow); + if (!himl) { + DeleteObject (ii.hbmColor); + DeleteObject (ii.hbmMask); + DeleteObject (handle); + return NULL; + } ImageList_Add (himl, ii.hbmColor, ii.hbmMask); DeleteObject (ii.hbmColor); DeleteObject (ii.hbmMask); @@ -1755,7 +1776,7 @@ TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1, i1, himl2, i2, dx, dy); - if ((himl1 == NULL) || (himl2 == NULL)) + if ((himl1 == NULL) || himl1->magic!=IMAGELIST_MAGIC || (himl2 == NULL) || himl2->magic!=IMAGELIST_MAGIC) return NULL; /* check indices */ @@ -1802,6 +1823,8 @@ } himlDst = ImageList_Create (cxDst, cyDst, ILC_MASK | ILC_COLOR, 1, 1); + if (!himlDst) + return NULL; if (himlDst) { hdcSrcImage = CreateCompatibleDC (0); @@ -2072,7 +2095,7 @@ TRACE("(himl=%p i=%d)\n", himl, i); - if (himl == NULL) { + if (himl == NULL || himl->magic!=IMAGELIST_MAGIC) { ERR("Invalid image list handle!\n"); return FALSE; } @@ -2208,7 +2231,7 @@ TRACE("%p %d %p %p\n", himl, i, hbmImage, hbmMask); - if (himl == NULL) { + if (himl == NULL || himl->magic!=IMAGELIST_MAGIC) { ERR("Invalid image list handle!\n"); return FALSE; } @@ -2283,7 +2306,7 @@ TRACE("(0x%lx 0x%x %p)\n", (DWORD)himl, i, hIcon); - if (himl == NULL) + if (himl == NULL || himl->magic!=IMAGELIST_MAGIC) return -1; if ((i >= himl->cMaxImage) || (i < -1)) return -1; @@ -2371,7 +2394,7 @@ { COLORREF clrOldBk; - if (himl == NULL) + if (himl == NULL || himl->magic!=IMAGELIST_MAGIC) return CLR_NONE; clrOldBk = himl->clrBk; @@ -2409,7 +2432,7 @@ INT dx, dy; BOOL visible; - if (InternalDrag.himl == NULL) + if (InternalDrag.himl == NULL || InternalDrag.himl->magic!=IMAGELIST_MAGIC) return FALSE; TRACE(" dxH=%d dyH=%d nX=%d nY=%d\n", @@ -2526,7 +2549,7 @@ { INT nCount; - if (!himl) + if (!himl || himl->magic!=IMAGELIST_MAGIC) return FALSE; /* remove all images */ @@ -2578,7 +2601,7 @@ TRACE("%p %d\n",himl,iImageCount); - if (!himl) + if (!himl || himl->magic!=IMAGELIST_MAGIC) return FALSE; if (himl->cCurImage >= iImageCount) return FALSE; @@ -2672,7 +2695,7 @@ BOOL WINAPI ImageList_SetOverlayImage (HIMAGELIST himl, INT iImage, INT iOverlay) { - if (!himl) + if (!himl || himl->magic!=IMAGELIST_MAGIC) return FALSE; if ((iOverlay < 1) || (iOverlay > MAX_OVERLAYIMAGE)) return FALSE; @@ -2805,7 +2828,7 @@ ILHEAD ilHead; int i; - if (!himl) + if (!himl || himl->magic!=IMAGELIST_MAGIC) return FALSE; ilHead.usMagic = (('L' << 8) | 'I');