Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-6072 Fix image index overrun and add test for js convolution filter #6088

Merged
merged 1 commit into from
Jan 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/filters/convolute_filter.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@
scx = x + cx - halfSide;

// eslint-disable-next-line max-depth
if (scy < 0 || scy > sh || scx < 0 || scx > sw) {
if (scy < 0 || scy >= sh || scx < 0 || scx >= sw) {
continue;
}

Expand Down
34 changes: 34 additions & 0 deletions test/unit/image_filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,40 @@
assert.ok(typeof filter.applyTo2d === 'function');
});

QUnit.test('applyTo2d values', function(assert) {
var filter = new fabric.Image.filters.Convolute({
matrix: [
0, 1, 0,
1, 2, 1,
0, 1, 0,
]
});
var pixelData = new Uint8Array([ // eslint-disable-line no-undef
0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255,
0, 0, 0, 255, 1, 2, 3, 255, 0, 0, 0, 255,
0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, 255,
]);
var expected = new Uint8Array([ // eslint-disable-line no-undef
0, 0, 0, 255, 1, 2, 3, 255, 0, 0, 0, 255,
1, 2, 3, 255, 2, 4, 6, 255, 1, 2, 3, 255,
0, 0, 0, 255, 1, 2, 3, 255, 0, 0, 0, 255,
]);
var imageData = context.createImageData(3, 3);
pixelData.forEach(function(el, i) {
imageData.data[i] = el;
});
var outCanvas = fabric.document.createElement('canvas');
var options = {
imageData: imageData,
ctx: outCanvas.getContext('2d'),
};
filter.applyTo2d(options);
var data = options.imageData.data;
data.forEach(function(el, i) {
assert.equal(el, expected[i]);
});
});

QUnit.test('toObject', function(assert) {
var filter = new fabric.Image.filters.Convolute({opaque: 1});
assert.ok(typeof filter.toObject === 'function');
Expand Down