瀏覽代碼

LibGL: Fix glTexImage2D texture dimension validation

This now verifies that width and height are a power of 2. The previous
check was nonsensical, probably because it was written against a spec
with improper text formatting, turning 2^x into 2*x :^)
Stephan Unverwerth 3 年之前
父節點
當前提交
7c60f4bbab
共有 1 個文件被更改,包括 3 次插入1 次删除
  1. 3 1
      Userland/Libraries/LibGL/SoftwareGLContext.cpp

+ 3 - 1
Userland/Libraries/LibGL/SoftwareGLContext.cpp

@@ -657,7 +657,9 @@ void SoftwareGLContext::gl_tex_image_2d(GLenum target, GLint level, GLint intern
     RETURN_WITH_ERROR_IF(type != GL_UNSIGNED_BYTE, GL_INVALID_VALUE);
     RETURN_WITH_ERROR_IF(level < 0 || level > Texture2D::LOG2_MAX_TEXTURE_SIZE, GL_INVALID_VALUE);
     RETURN_WITH_ERROR_IF(width < 0 || height < 0 || width > (2 + Texture2D::MAX_TEXTURE_SIZE) || height > (2 + Texture2D::MAX_TEXTURE_SIZE), GL_INVALID_VALUE);
-    RETURN_WITH_ERROR_IF((width & 2) != 0 || (height & 2) != 0, GL_INVALID_VALUE);
+    // Check if width and height are a power of 2
+    RETURN_WITH_ERROR_IF((width & (width - 1)) != 0, GL_INVALID_VALUE);
+    RETURN_WITH_ERROR_IF((height & (height - 1)) != 0, GL_INVALID_VALUE);
     RETURN_WITH_ERROR_IF(border < 0 || border > 1, GL_INVALID_VALUE);
 
     m_active_texture_unit->bound_texture_2d()->upload_texture_data(target, level, internal_format, width, height, border, format, type, data, m_unpack_row_length);