Skip to content

Commit de69d3a

Browse files
committed
double-free via g_object_unref that could crash
Fixes #2486
1 parent 2f9de7c commit de69d3a

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/Image.cc

+1-9
Original file line numberDiff line numberDiff line change
@@ -1470,8 +1470,6 @@ cairo_status_t
14701470
Image::loadSVGFromBuffer(uint8_t *buf, unsigned len) {
14711471
_is_svg = true;
14721472

1473-
cairo_status_t status;
1474-
14751473
if (NULL == (_rsvg = rsvg_handle_new_from_data(buf, len, nullptr))) {
14761474
return CAIRO_STATUS_READ_ERROR;
14771475
}
@@ -1484,13 +1482,7 @@ Image::loadSVGFromBuffer(uint8_t *buf, unsigned len) {
14841482
width = naturalWidth = d_width;
14851483
height = naturalHeight = d_height;
14861484

1487-
status = renderSVGToSurface();
1488-
if (status != CAIRO_STATUS_SUCCESS) {
1489-
g_object_unref(_rsvg);
1490-
return status;
1491-
}
1492-
1493-
return CAIRO_STATUS_SUCCESS;
1485+
return renderSVGToSurface();
14941486
}
14951487

14961488
/*

test/canvas.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -2513,4 +2513,13 @@ describe('Canvas', function () {
25132513
assert.throws(() => { ctx.beginTag('Link', {}) })
25142514
})
25152515
})
2516+
2517+
describe('loadImage', function () {
2518+
it('doesn\'t crash when you don\'t specify width and height', async function () {
2519+
await assert.rejects(async () => {
2520+
const svg = `<svg xmlns="http://www.w3.org/2000/svg"><path d="M1,1"/></svg>`;
2521+
await loadImage(Buffer.from(svg));
2522+
});
2523+
});
2524+
});
25162525
})

0 commit comments

Comments
 (0)