Bug 966630 - Clamp level to TexImage operations to [0..31]. r=jgilbert, a=abillings
authorDan Glastonbury <dglastonbury@mozilla.com>
Mon, 14 Apr 2014 17:27:24 +1000
changeset 183774 17432cc5074d
parent 183773 b30d5dfe0421
child 183775 838a0ac967ae
push id3481
push userryanvm@gmail.com
push date2014-04-16 15:27 +0000
Treeherderresults
reviewersjgilbert, abillings
bugs966630
milestone29.0
Bug 966630 - Clamp level to TexImage operations to [0..31]. r=jgilbert, a=abillings
content/canvas/src/WebGLContextValidate.cpp
--- a/content/canvas/src/WebGLContextValidate.cpp
+++ b/content/canvas/src/WebGLContextValidate.cpp
@@ -439,16 +439,29 @@ bool WebGLContext::ValidateLevelWidthHei
 {
     GLsizei maxTextureSize = MaxTextureSizeForTarget(target);
 
     if (level < 0) {
         ErrorInvalidValue("%s: level must be >= 0", info);
         return false;
     }
 
+    /* Bug 966630: maxTextureSize >> level runs into "undefined"
+     * behaviour depending on ISA. For example, on Intel shifts
+     * amounts are mod 64 (in 64-bit mode on 64-bit dest) and mod 32
+     * otherwise. This means 16384 >> 0x10000001 == 8192 which isn't
+     * what would be expected. Make the required behaviour explicit by
+     * clamping to a shift of 31 bits if level is greater than that
+     * ammount. This will give 0 that if (!maxAllowedSize) is
+     * expecting.
+     */
+
+    if (level > 31)
+        level = 31;
+
     GLsizei maxAllowedSize = maxTextureSize >> level;
 
     if (!maxAllowedSize) {
         ErrorInvalidValue("%s: 2^level exceeds maximum texture size", info);
         return false;
     }
 
     if (width < 0 || height < 0) {