From 38cd92d482e05fc4f20ef9b52b80ef57277af0e9 Mon Sep 17 00:00:00 2001 From: webgurucan Date: Thu, 28 Nov 2019 21:20:32 +0000 Subject: [PATCH] Handle zero-length Buffers in Node.js v13.2.0+ These now use nullptr internally - see https://github.com/nodejs/node/pull/30339 --- docs/changelog.md | 2 ++ src/common.cc | 3 ++- src/common.h | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index cd5c97d8..2ad8aa1c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -6,6 +6,8 @@ Requires libvips v8.8.1. #### v0.23.4 - TBD +* Handle zero-length Buffer objects when using Node.js v13.2.0+. + * Improve thread safety by using copy-on-write when updating metadata. [#1986](https://github.com/lovell/sharp/issues/1986) diff --git a/src/common.cc b/src/common.cc index 38727e3a..8c9b4824 100644 --- a/src/common.cc +++ b/src/common.cc @@ -58,6 +58,7 @@ namespace sharp { v8::Local buffer = AttrAs(input, "buffer"); descriptor->bufferLength = node::Buffer::Length(buffer); descriptor->buffer = node::Buffer::Data(buffer); + descriptor->isBuffer = TRUE; buffersToPersist.push_back(buffer); } descriptor->failOnError = AttrTo(input, "failOnError"); @@ -246,7 +247,7 @@ namespace sharp { std::tuple OpenInput(InputDescriptor *descriptor, VipsAccess accessMethod) { VImage image; ImageType imageType; - if (descriptor->buffer != nullptr) { + if (descriptor->isBuffer) { if (descriptor->rawChannels > 0) { // Raw, uncompressed pixel data image = VImage::new_from_memory(descriptor->buffer, descriptor->bufferLength, diff --git a/src/common.h b/src/common.h index e4b03d5c..29977de3 100644 --- a/src/common.h +++ b/src/common.h @@ -49,6 +49,7 @@ namespace sharp { char *buffer; bool failOnError; size_t bufferLength; + bool isBuffer; double density; int rawChannels; int rawWidth; @@ -64,6 +65,7 @@ namespace sharp { buffer(nullptr), failOnError(TRUE), bufferLength(0), + isBuffer(FALSE), density(72.0), rawChannels(0), rawWidth(0),