Auto merge of #13898 - anholt:webgl-texture-fixes, r=emilio

webgl: texture size validation fixes

<!-- Please describe your changes on the following line: -->
This pull request fixes the errors in texture-size-limit.html.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13898)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-10-24 00:52:57 -05:00 committed by GitHub
commit f3973a0d3b
6 changed files with 1172 additions and 1547 deletions

View file

@ -163,18 +163,18 @@ impl<'a> WebGLValidator for CommonTexImage2DValidator<'a> {
return Err(TexImageValidationError::NegativeDimension);
}
// GL_INVALID_VALUE is generated if width or height is greater than
// GL_MAX_TEXTURE_SIZE when target is GL_TEXTURE_2D or
// GL_MAX_CUBE_MAP_TEXTURE_SIZE when target is not GL_TEXTURE_2D.
if self.width as u32 > max_size || self.height as u32 > max_size {
self.context.webgl_error(InvalidValue);
return Err(TexImageValidationError::TextureTooBig);
}
let width = self.width as u32;
let height = self.height as u32;
let level = self.level as u32;
// GL_INVALID_VALUE is generated if width or height is greater than
// GL_MAX_TEXTURE_SIZE when target is GL_TEXTURE_2D or
// GL_MAX_CUBE_MAP_TEXTURE_SIZE when target is not GL_TEXTURE_2D.
if width > max_size >> level || height > max_size >> level {
self.context.webgl_error(InvalidValue);
return Err(TexImageValidationError::TextureTooBig);
}
// GL_INVALID_VALUE is generated if level is greater than zero and the
// texture is not power of two.
if level > 0 && (!width.is_power_of_two() || !height.is_power_of_two()) {

View file

@ -2359,7 +2359,13 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
Some(data) => data,
};
if buff.len() != expected_byte_length as usize {
// From the WebGL spec:
//
// "If pixels is non-null but its size is less than what
// is required by the specified width, height, format,
// type, and pixel storage parameters, generates an
// INVALID_OPERATION error."
if buff.len() < expected_byte_length as usize {
return Ok(self.webgl_error(InvalidOperation));
}
@ -2459,8 +2465,13 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
Some(data) => data,
};
if expected_byte_length != 0 &&
buff.len() != expected_byte_length as usize {
// From the WebGL spec:
//
// "If pixels is non-null but its size is less than what
// is required by the specified width, height, format,
// type, and pixel storage parameters, generates an
// INVALID_OPERATION error."
if buff.len() < expected_byte_length as usize {
return Ok(self.webgl_error(InvalidOperation));
}