Skip to content

Commit fec8fe9

Browse files
committed
nicer error reporting when svg width/height missing
1 parent de69d3a commit fec8fe9

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Image.cc

+5
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,11 @@ Image::loadSVGFromBuffer(uint8_t *buf, unsigned len) {
14821482
width = naturalWidth = d_width;
14831483
height = naturalHeight = d_height;
14841484

1485+
if (width <= 0 || height <= 0) {
1486+
this->errorInfo.set("Width and height must be set on the svg element");
1487+
return CAIRO_STATUS_READ_ERROR;
1488+
}
1489+
14851490
return renderSVGToSurface();
14861491
}
14871492

test/canvas.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -2519,6 +2519,9 @@ describe('Canvas', function () {
25192519
await assert.rejects(async () => {
25202520
const svg = `<svg xmlns="http://www.w3.org/2000/svg"><path d="M1,1"/></svg>`;
25212521
await loadImage(Buffer.from(svg));
2522+
}, {
2523+
name: "Error",
2524+
message: "Width and height must be set on the svg element"
25222525
});
25232526
});
25242527
});

0 commit comments

Comments
 (0)