Skip to content

Commit

Permalink
Add canvas usability checks to drawImage()
Browse files Browse the repository at this point in the history
  • Loading branch information
pylbrecht committed Feb 3, 2020
1 parent ed0973f commit 423b86e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
10 changes: 10 additions & 0 deletions components/script/canvas_state.rs
Expand Up @@ -382,9 +382,19 @@ impl CanvasState {
) -> ErrorResult {
let result = match image {
CanvasImageSource::HTMLCanvasElement(ref canvas) => {
// https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument
if !canvas.is_valid() {
return Err(Error::InvalidState);
}

self.draw_html_canvas_element(&canvas, htmlcanvas, sx, sy, sw, sh, dx, dy, dw, dh)
},
CanvasImageSource::OffscreenCanvas(ref canvas) => {
// https://html.spec.whatwg.org/multipage/#check-the-usability-of-the-image-argument
if !canvas.is_valid() {
return Err(Error::InvalidState);
}

self.draw_offscreen_canvas(&canvas, htmlcanvas, sx, sy, sw, sh, dx, dy, dw, dh)
},
CanvasImageSource::HTMLImageElement(ref image) => {
Expand Down
4 changes: 4 additions & 0 deletions components/script/dom/offscreencanvas.rs
Expand Up @@ -138,6 +138,10 @@ impl OffscreenCanvas {
));
Some(context)
}

pub fn is_valid(&self) -> bool {
self.Width() != 0 && self.Height() != 0
}
}

impl OffscreenCanvasMethods for OffscreenCanvas {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 423b86e

Please sign in to comment.