Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d24a127

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

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

‎CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ project adheres to [Semantic Versioning](http://semver.org/).
99
==================
1010
### Changed
1111
### Added
12+
1213
### Fixed
14+
* Fix a crash when SVGs without width or height are loaded (#2486)
1315

1416
3.1.0
1517
==================

‎src/Image.cc

Lines changed: 1 addition & 9 deletions
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

Lines changed: 9 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /