From 7f2637bfe5ef1764882a123a8942e60632730bdf Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Thu, 28 Feb 2013 20:30:22 +0100
Subject: Fix Bug 695: WGLExt.wglChoosePixelFormatARB causes buffer underflow
 due to a higher reported number of configs than buffer size

"I encountered a case on an NVidia Quadro 3500 fx where the call to
WGLExt.wglChoosePixelFormatARB in WindowsWGLGraphicsConfiguration (currently
line 355) returns 264 in numFormatsTmp despite 256 being passed in for the
maximum number of formats. This results in a buffer underflow on line 368 since
pformatsTmp only has 256 values and it's trying to copy 264 values."

Fixed in WindowsWGLGraphicsConfiguration and WindowsPbufferWGLDrawable.
---
 .../classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java')

diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java
index 6c7893c3e..b65f5dd2f 100644
--- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java
+++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java
@@ -173,7 +173,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable {
                                             pformats, nformatsTmp)) {
           throw new GLException("pbuffer creation error: wglChoosePixelFormat() failed");
         }
-        final int nformats = nformatsTmp.get(0);
+        final int nformats = Math.min(nformatsTmp.get(0), WindowsWGLGraphicsConfiguration.MAX_PFORMATS);
         if (nformats <= 0) {
           throw new GLException("pbuffer creation error: Couldn't find a suitable pixel format");
         }
-- 
cgit v1.2.3