mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Improve error message for SVG render above limit #3167
This commit is contained in:
parent
926572b41e
commit
5d36f5f699
@ -8,6 +8,9 @@ Requires libvips v8.12.2
|
|||||||
|
|
||||||
* Increase control over sensitivity to invalid images via `failOn`, deprecate `failOnError` (equivalent to `failOn: 'warning'`).
|
* Increase control over sensitivity to invalid images via `failOn`, deprecate `failOnError` (equivalent to `failOn: 'warning'`).
|
||||||
|
|
||||||
|
* Improve error message when attempting to render SVG input greater than 32767x32767.
|
||||||
|
[#3167](https://github.com/lovell/sharp/issues/3167)
|
||||||
|
|
||||||
* Ensure `create` input image has correct bit depth and colour space.
|
* Ensure `create` input image has correct bit depth and colour space.
|
||||||
[#3139](https://github.com/lovell/sharp/issues/3139)
|
[#3139](https://github.com/lovell/sharp/issues/3139)
|
||||||
|
|
||||||
|
@ -241,8 +241,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
// Reload SVG file
|
// Reload SVG file
|
||||||
image = VImage::svgload(const_cast<char*>(baton->input->file.data()), option);
|
image = VImage::svgload(const_cast<char*>(baton->input->file.data()), option);
|
||||||
}
|
}
|
||||||
|
|
||||||
sharp::SetDensity(image, baton->input->density);
|
sharp::SetDensity(image, baton->input->density);
|
||||||
|
if (image.width() > 32767 || image.height() > 32767) {
|
||||||
|
throw vips::VError("Input SVG image will exceed 32767x32767 pixel limit when scaled");
|
||||||
|
}
|
||||||
} else if (inputImageType == sharp::ImageType::PDF) {
|
} else if (inputImageType == sharp::ImageType::PDF) {
|
||||||
option->set("n", baton->input->pages);
|
option->set("n", baton->input->pages);
|
||||||
option->set("page", baton->input->page);
|
option->set("page", baton->input->page);
|
||||||
@ -260,6 +262,10 @@ class PipelineWorker : public Napi::AsyncWorker {
|
|||||||
|
|
||||||
sharp::SetDensity(image, baton->input->density);
|
sharp::SetDensity(image, baton->input->density);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (inputImageType == sharp::ImageType::SVG && (image.width() > 32767 || image.height() > 32767)) {
|
||||||
|
throw vips::VError("Input SVG image exceeds 32767x32767 pixel limit");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Any pre-shrinking may already have been done
|
// Any pre-shrinking may already have been done
|
||||||
|
@ -136,6 +136,20 @@ describe('SVG input', function () {
|
|||||||
assert.strictEqual(info.channels, 4);
|
assert.strictEqual(info.channels, 4);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Fails to render SVG larger than 32767x32767', () =>
|
||||||
|
assert.rejects(
|
||||||
|
() => sharp(Buffer.from('<svg width="32768" height="1" />')).toBuffer(),
|
||||||
|
/Input SVG image exceeds 32767x32767 pixel limit/
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
it('Fails to render scaled SVG larger than 32767x32767', () =>
|
||||||
|
assert.rejects(
|
||||||
|
() => sharp(Buffer.from('<svg width="32767" height="1" />')).resize(32768).toBuffer(),
|
||||||
|
/Input SVG image will exceed 32767x32767 pixel limit when scaled/
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
it('Detects SVG passed as a string', () =>
|
it('Detects SVG passed as a string', () =>
|
||||||
assert.rejects(
|
assert.rejects(
|
||||||
() => sharp('<svg></svg>').toBuffer(),
|
() => sharp('<svg></svg>').toBuffer(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user