[USER32] Show Debug Log Message when unhandled PNG found in ICO file. (#5566)
authorDoug Lyons <douglyons@douglyons.com>
Tue, 12 Mar 2024 07:45:22 +0000 (02:45 -0500)
committerGitHub <noreply@github.com>
Tue, 12 Mar 2024 07:45:22 +0000 (16:45 +0900)
Detect the PNG data in ICO files and print an appropriate message to the debug log.
JIRA issue: CORE-19107

win32ss/user/user32/windows/cursoricon.c

index a3f8a48..eb160a8 100644 (file)
@@ -179,6 +179,12 @@ static int bitmap_info_size( const BITMAPINFO * info, WORD coloruse )
 static int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, LONG *width,
                               LONG *height, WORD *bpp, DWORD *compr )
 {
+    #define CR 13
+    #define LF 10
+    #define EOFM 26 // DOS End Of File Marker
+    #define HighBitDetect 0x89 // Byte with high bit set to test if not 7-bit
+    /* wine's definition */
+    static const BYTE png_sig_pattern[] = { HighBitDetect, 'P', 'N', 'G', CR, LF, EOFM, LF };
     if (header->biSize == sizeof(BITMAPCOREHEADER))
     {
         const BITMAPCOREHEADER *core = (const BITMAPCOREHEADER *)header;
@@ -198,7 +204,15 @@ static int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, LONG *width,
         *compr  = header->biCompression;
         return 1;
     }
-    ERR("(%d): unknown/wrong size for header\n", header->biSize );
+    if (memcmp(&header->biSize, png_sig_pattern, sizeof(png_sig_pattern)) == 0)
+    {
+        ERR("Cannot yet display PNG icons\n");
+        /* for PNG format details see https://en.wikipedia.org/wiki/PNG */
+    }
+    else
+    {
+        ERR("Unknown/wrong size for header of 0x%x\n", header->biSize );
+    }
     return -1;
 }
 
@@ -1377,7 +1391,10 @@ CURSORICON_LoadFromFileW(
 
     /* Do the dance */
     if(!CURSORICON_GetCursorDataFromBMI(&cursorData, (BITMAPINFO*)(&bits[entry->dwDIBOffset])))
-        goto end;
+        {
+            ERR("Failing File is \n    '%S'.\n", lpszName);
+            goto end;
+        }
 
     hCurIcon = NtUserxCreateEmptyCurObject(FALSE);
     if(!hCurIcon)