Skip to content

Commit

Permalink
Reject kernelMatrix with 0 width in convolveMatrix CanvasFilters.
Browse files Browse the repository at this point in the history
Only the height was checked (rejecting `[]` kernels) but kernels with
zero width like `[[], []]` were incorrectly accepted.

The current CanvasFilter specification is defined by reusing the
SVG specification for how the filters attributes work
(whatwg/html#6763). For the
"feConvolveMatrix" filter, the SVG specification says
(https://www.w3.org/TR/SVG11/filters.html#feConvolveMatrixElement):

"Attribute definitions:
- order = "<number-optional-number>"
  Indicates the number of cells in each dimension for ‘kernelMatrix’.
  The values provided must be <integer>s greater than zero. The first
  number, <orderX>, indicates the number of columns in the matrix.
  The second number, <orderY>, indicates the number of rows in the
  matrix. If <orderY> is not provided, it defaults to <orderX>."

Change-Id: I23baf05db73e679a52cd9d553d7c6308d91b56f9
Bug: 1428652
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4377066
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Commit-Queue: Jean-Philippe Gravel <jpgravel@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1124423}
  • Loading branch information
graveljp authored and Chromium LUCI CQ committed Mar 30, 2023
1 parent 2c8ac61 commit 3697146
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ absl::optional<KernelMatrix> GetKernelMatrix(const Dictionary& dict,
absl::optional<Vector<Vector<float>>> km_input =
dict.Get<IDLSequence<IDLSequence<IDLFloat>>>("kernelMatrix",
exception_state);
if (!km_input.has_value() || km_input->size() == 0) {
if (!km_input.has_value() || km_input->size() == 0 ||
(km_input->size() >= 2 && km_input->at(0).size() == 0)) {
exception_state.ThrowTypeError(
"Failed to construct convolve matrix filter. 'kernelMatrix' must be an "
"array of arrays of numbers representing an n by m matrix.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ <h1>2d.filter.canvasFilterObject.convolveMatrix.exceptions.tentative</h1>
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[1, 0], 0]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[1, 0], [0, Infinity]]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: []}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [1]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [1, 2, 3, 4]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[], []]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[1, 2], []]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[], [1, 2]]}); });
// This should not throw an error
ctx.filter = new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[]]});
ctx.filter = new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[1]]});


});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ <h1>2d.filter.canvasFilterObject.convolveMatrix.exceptions.tentative</h1>
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[1, 0], 0]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[1, 0], [0, Infinity]]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: []}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [1]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [1, 2, 3, 4]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[], []]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[1, 2], []]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[], [1, 2]]}); });
// This should not throw an error
ctx.filter = new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[]]});
ctx.filter = new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[1]]});
})(canvas, ctx);
t.done();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatr
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[1, 0], 0]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[1, 0], [0, Infinity]]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: []}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [1]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [1, 2, 3, 4]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[], []]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[1, 2], []]}); });
assert_throws_js(TypeError, function() { new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[], [1, 2]]}); });
// This should not throw an error
ctx.filter = new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[]]});
ctx.filter = new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[1]]});
t.done();

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,14 @@
@assert throws TypeError new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[1, 0], 0]});
@assert throws TypeError new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[1, 0], [0, Infinity]]});
@assert throws TypeError new CanvasFilter({filter: "convolveMatrix", kernelMatrix: []});
@assert throws TypeError new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [1]});
@assert throws TypeError new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [1, 2, 3, 4]});
@assert throws TypeError new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[], []]});
@assert throws TypeError new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[1, 2], []]});
@assert throws TypeError new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[], [1, 2]]});
// This should not throw an error
ctx.filter = new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[]]});
ctx.filter = new CanvasFilter({filter: "convolveMatrix", kernelMatrix: [[1]]});
- name: 2d.filter.canvasFilterObject.componentTransfer.linear.tentative
desc: Test pixels on CanvasFilter() componentTransfer with linear type
Expand Down

0 comments on commit 3697146

Please sign in to comment.