Skip to content
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
8 changes: 4 additions & 4 deletions lib/operation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,10 @@ function blur (options) {
function dilate (width) {
if (!is.defined(width)) {
this.options.dilateWidth = 1;
} else if (is.integer(width) && width > 0) {
} else if (is.integer(width) && is.inRange(width, 1, 65536)) {
this.options.dilateWidth = width;
} else {
throw is.invalidParameterError('dilate', 'positive integer', dilate);
throw is.invalidParameterError('width', 'integer between 1 and 65536', width);
}
return this;
}
Expand All @@ -447,10 +447,10 @@ function dilate (width) {
function erode (width) {
if (!is.defined(width)) {
this.options.erodeWidth = 1;
} else if (is.integer(width) && width > 0) {
} else if (is.integer(width) && is.inRange(width, 1, 65536)) {
this.options.erodeWidth = width;
} else {
throw is.invalidParameterError('erode', 'positive integer', erode);
throw is.invalidParameterError('width', 'integer between 1 and 65536', width);
}
return this;
}
Expand Down
7 changes: 7 additions & 0 deletions test/unit/dilate.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@ suite('Dilate', () => {
sharp(fixtures.inputJpg).dilate(-1);
});
});

test('oversized dilation width is rejected', (t) => {
t.plan(1);
t.assert.throws(() => {
sharp(fixtures.inputJpg).dilate(2147483648);
});
});
});
7 changes: 7 additions & 0 deletions test/unit/erode.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@ suite('Erode', () => {
sharp(fixtures.inputJpg).erode(-1);
});
});

test('oversized erosion width is rejected', (t) => {
t.plan(1);
t.assert.throws(() => {
sharp(fixtures.inputJpg).erode(2147483648);
});
});
});