Skip to content

Commit b1fe25f

Browse files
committed
bail early when setting zero-length image source
the pointer can actually be null in this case which triggers a ubsan panic
1 parent fe7ec6d commit b1fe25f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/Image.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ Image::SetSource(const Napi::CallbackInfo& info){
268268

269269
cairo_status_t
270270
Image::loadFromBuffer(uint8_t *buf, unsigned len) {
271+
if (len == 0) return CAIRO_STATUS_READ_ERROR;
272+
271273
uint8_t data[4] = {0};
272274
memcpy(data, buf, (len < 4 ? len : 4) * sizeof(uint8_t));
273275

0 commit comments

Comments
 (0)