Treat invalid pixel types as PFD_TYPE_RGBA in wglChoosePixelFormat (opengl32) Accepted

Revisions: 

Revision 1

user image Michael Müller Author
02 Sep. 17

Fixes the opengl related crash from https://bugs.winehq.org/show_bug.cgi?id=43638

Single files Merged diff Tar archive
You have unsaved changes. Press CTRL + ENTER in a text field to submit your comments.

0001-opengl32-Treat-invalid-pixel-types-as-PFD_TYPE_RGBA-.patch (2 comments)

From 546f388411e841a7a84dd472a7e78177dc32c33c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Sat, 2 Sep 2017 04:20:21 +0200
Subject: opengl32: Treat invalid pixel types as PFD_TYPE_RGBA in
wglChoosePixelFormat.
---
dlls/opengl32/tests/opengl.c | 59 ++++++++++++++++++++++++++++----------------
dlls/opengl32/wgl.c | 2 +-
2 files changed, 39 insertions(+), 22 deletions(-)
diff --git a/dlls/opengl32/tests/opengl.c b/dlls/opengl32/tests/opengl.c
index db5ad76e96..50f908ab08 100644
--- a/dlls/opengl32/tests/opengl.c
+++ b/dlls/opengl32/tests/opengl.c
@@ -242,7 +242,7 @@ static void test_pbuffers(HDC hdc)
else skip("Pbuffer test for offscreen pixelformat skipped as no offscreen-only format with pbuffer capabilities has been found\n");
}
-static int test_pfd(const PIXELFORMATDESCRIPTOR *pfd)
+static int test_pfd(const PIXELFORMATDESCRIPTOR *pfd, PIXELFORMATDESCRIPTOR *fmt)
{
int pf;
HDC hdc;
@@ -255,6 +255,12 @@ static int test_pfd(const PIXELFORMATDESCRIPTOR *pfd)
hdc = GetDC( hwnd );
pf = ChoosePixelFormat( hdc, pfd );
+ if (pf && fmt)
+ {
+ memset(&fmt, 0, sizeof(*fmt));
user image Sebastian Lackner
06 Sep. 17

This zeros the memory address instead of the content. Could you please verify that the test still works after fixing this line?

user image Michael Müller Author
07 Sep. 17

It still works.

+ ok(DescribePixelFormat( hdc, pf, sizeof(*fmt), fmt ),
+ "DescribePixelFormat failed with error: %u\n", GetLastError());
+ }
ReleaseDC( hwnd, hdc );
DestroyWindow( hwnd );
@@ -282,57 +288,68 @@ static void test_choosepixelformat(void)
0, /* reserved */
0, 0, 0 /* layer masks */
};
+ PIXELFORMATDESCRIPTOR ret_fmt;
- ok( test_pfd(&pfd), "Simple pfd failed\n" );
+ ok( test_pfd(&pfd, NULL), "Simple pfd failed\n" );
pfd.dwFlags |= PFD_DOUBLEBUFFER_DONTCARE;
- ok( test_pfd(&pfd), "PFD_DOUBLEBUFFER_DONTCARE failed\n" );
+ ok( test_pfd(&pfd, NULL), "PFD_DOUBLEBUFFER_DONTCARE failed\n" );
pfd.dwFlags |= PFD_STEREO_DONTCARE;
- ok( test_pfd(&pfd), "PFD_DOUBLEBUFFER_DONTCARE|PFD_STEREO_DONTCARE failed\n" );
+ ok( test_pfd(&pfd, NULL), "PFD_DOUBLEBUFFER_DONTCARE|PFD_STEREO_DONTCARE failed\n" );
pfd.dwFlags &= ~PFD_DOUBLEBUFFER_DONTCARE;
- ok( test_pfd(&pfd), "PFD_STEREO_DONTCARE failed\n" );
+ ok( test_pfd(&pfd, NULL), "PFD_STEREO_DONTCARE failed\n" );
pfd.dwFlags &= ~PFD_STEREO_DONTCARE;
+ pfd.iPixelType = 32;
+ ok( test_pfd(&pfd, &ret_fmt), "Invalid pixel format 32 failed\n" );
+ ok( ret_fmt.iPixelType == PFD_TYPE_RGBA, "Expected pixel type PFD_TYPE_RGBA, got %d\n", ret_fmt.iPixelType );
+ pfd.iPixelType = 33;
+ ok( test_pfd(&pfd, &ret_fmt), "Invalid pixel format 33 failed\n" );
+ ok( ret_fmt.iPixelType == PFD_TYPE_RGBA, "Expected pixel type PFD_TYPE_RGBA, got %d\n", ret_fmt.iPixelType );
+ pfd.iPixelType = 15;
+ ok( test_pfd(&pfd, &ret_fmt), "Invalid pixel format 15 failed\n" );
+ ok( ret_fmt.iPixelType == PFD_TYPE_RGBA, "Expected pixel type PFD_TYPE_RGBA, got %d\n", ret_fmt.iPixelType );
+ pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
- ok( test_pfd(&pfd), "Simple pfd failed\n" );
+ ok( test_pfd(&pfd, NULL), "Simple pfd failed\n" );
pfd.dwFlags |= PFD_DOUBLEBUFFER_DONTCARE;
- ok( test_pfd(&pfd), "PFD_DOUBLEBUFFER_DONTCARE failed\n" );
+ ok( test_pfd(&pfd, NULL), "PFD_DOUBLEBUFFER_DONTCARE failed\n" );
pfd.dwFlags |= PFD_STEREO_DONTCARE;
- ok( test_pfd(&pfd), "PFD_DOUBLEBUFFER_DONTCARE|PFD_STEREO_DONTCARE failed\n" );
+ ok( test_pfd(&pfd, NULL), "PFD_DOUBLEBUFFER_DONTCARE|PFD_STEREO_DONTCARE failed\n" );
pfd.dwFlags &= ~PFD_DOUBLEBUFFER_DONTCARE;
- ok( test_pfd(&pfd), "PFD_STEREO_DONTCARE failed\n" );
+ ok( test_pfd(&pfd, NULL), "PFD_STEREO_DONTCARE failed\n" );
pfd.dwFlags &= ~PFD_STEREO_DONTCARE;
pfd.cColorBits = 0;
pfd.cAlphaBits = 8;
- ok( test_pfd(&pfd), "Simple pfd failed\n" );
+ ok( test_pfd(&pfd, NULL), "Simple pfd failed\n" );
pfd.dwFlags |= PFD_DOUBLEBUFFER_DONTCARE;
- ok( test_pfd(&pfd), "PFD_DOUBLEBUFFER_DONTCARE failed\n" );
+ ok( test_pfd(&pfd, NULL), "PFD_DOUBLEBUFFER_DONTCARE failed\n" );
pfd.dwFlags |= PFD_STEREO_DONTCARE;
- ok( test_pfd(&pfd), "PFD_DOUBLEBUFFER_DONTCARE|PFD_STEREO_DONTCARE failed\n" );
+ ok( test_pfd(&pfd, NULL), "PFD_DOUBLEBUFFER_DONTCARE|PFD_STEREO_DONTCARE failed\n" );
pfd.dwFlags &= ~PFD_DOUBLEBUFFER_DONTCARE;
- ok( test_pfd(&pfd), "PFD_STEREO_DONTCARE failed\n" );
+ ok( test_pfd(&pfd, NULL), "PFD_STEREO_DONTCARE failed\n" );
pfd.dwFlags &= ~PFD_STEREO_DONTCARE;
pfd.cAlphaBits = 0;
pfd.cStencilBits = 8;
- ok( test_pfd(&pfd), "Simple pfd failed\n" );
+ ok( test_pfd(&pfd, NULL), "Simple pfd failed\n" );
pfd.dwFlags |= PFD_DOUBLEBUFFER_DONTCARE;
- ok( test_pfd(&pfd), "PFD_DOUBLEBUFFER_DONTCARE failed\n" );
+ ok( test_pfd(&pfd, NULL), "PFD_DOUBLEBUFFER_DONTCARE failed\n" );
pfd.dwFlags |= PFD_STEREO_DONTCARE;
- ok( test_pfd(&pfd), "PFD_DOUBLEBUFFER_DONTCARE|PFD_STEREO_DONTCARE failed\n" );
+ ok( test_pfd(&pfd, NULL), "PFD_DOUBLEBUFFER_DONTCARE|PFD_STEREO_DONTCARE failed\n" );
pfd.dwFlags &= ~PFD_DOUBLEBUFFER_DONTCARE;
- ok( test_pfd(&pfd), "PFD_STEREO_DONTCARE failed\n" );
+ ok( test_pfd(&pfd, NULL), "PFD_STEREO_DONTCARE failed\n" );
pfd.dwFlags &= ~PFD_STEREO_DONTCARE;
pfd.cStencilBits = 0;
pfd.cAuxBuffers = 1;
- ok( test_pfd(&pfd), "Simple pfd failed\n" );
+ ok( test_pfd(&pfd, NULL), "Simple pfd failed\n" );
pfd.dwFlags |= PFD_DOUBLEBUFFER_DONTCARE;
- ok( test_pfd(&pfd), "PFD_DOUBLEBUFFER_DONTCARE failed\n" );
+ ok( test_pfd(&pfd, NULL), "PFD_DOUBLEBUFFER_DONTCARE failed\n" );
pfd.dwFlags |= PFD_STEREO_DONTCARE;
- ok( test_pfd(&pfd), "PFD_DOUBLEBUFFER_DONTCARE|PFD_STEREO_DONTCARE failed\n" );
+ ok( test_pfd(&pfd, NULL), "PFD_DOUBLEBUFFER_DONTCARE|PFD_STEREO_DONTCARE failed\n" );
pfd.dwFlags &= ~PFD_DOUBLEBUFFER_DONTCARE;
- ok( test_pfd(&pfd), "PFD_STEREO_DONTCARE failed\n" );
+ ok( test_pfd(&pfd, NULL), "PFD_STEREO_DONTCARE failed\n" );
pfd.dwFlags &= ~PFD_STEREO_DONTCARE;
pfd.cAuxBuffers = 0;
}
diff --git a/dlls/opengl32/wgl.c b/dlls/opengl32/wgl.c
index ae230bfcb0..25920b6b11 100644
--- a/dlls/opengl32/wgl.c
+++ b/dlls/opengl32/wgl.c
@@ -480,7 +480,7 @@ INT WINAPI wglChoosePixelFormat(HDC hdc, const PIXELFORMATDESCRIPTOR* ppfd)
{
if (!wglDescribePixelFormat( hdc, i, sizeof(format), &format )) continue;
- if (ppfd->iPixelType != format.iPixelType)
+ if ((ppfd->iPixelType == PFD_TYPE_COLORINDEX) != (format.iPixelType == PFD_TYPE_COLORINDEX))
{
TRACE( "pixel type mismatch for iPixelFormat=%d\n", i );
continue;
--
2.14.1