Skip to content

Commit 38cd92d

Browse files
committed
Handle zero-length Buffers in Node.js v13.2.0+
These now use nullptr internally - see nodejs/node#30339
1 parent 29537c1 commit 38cd92d

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

docs/changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Requires libvips v8.8.1.
66

77
#### v0.23.4 - TBD
88

9+
* Handle zero-length Buffer objects when using Node.js v13.2.0+.
10+
911
* Improve thread safety by using copy-on-write when updating metadata.
1012
[#1986](https://github.com/lovell/sharp/issues/1986)
1113

src/common.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ namespace sharp {
5858
v8::Local<v8::Object> buffer = AttrAs<v8::Object>(input, "buffer");
5959
descriptor->bufferLength = node::Buffer::Length(buffer);
6060
descriptor->buffer = node::Buffer::Data(buffer);
61+
descriptor->isBuffer = TRUE;
6162
buffersToPersist.push_back(buffer);
6263
}
6364
descriptor->failOnError = AttrTo<bool>(input, "failOnError");
@@ -246,7 +247,7 @@ namespace sharp {
246247
std::tuple<VImage, ImageType> OpenInput(InputDescriptor *descriptor, VipsAccess accessMethod) {
247248
VImage image;
248249
ImageType imageType;
249-
if (descriptor->buffer != nullptr) {
250+
if (descriptor->isBuffer) {
250251
if (descriptor->rawChannels > 0) {
251252
// Raw, uncompressed pixel data
252253
image = VImage::new_from_memory(descriptor->buffer, descriptor->bufferLength,

src/common.h

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace sharp {
4949
char *buffer;
5050
bool failOnError;
5151
size_t bufferLength;
52+
bool isBuffer;
5253
double density;
5354
int rawChannels;
5455
int rawWidth;
@@ -64,6 +65,7 @@ namespace sharp {
6465
buffer(nullptr),
6566
failOnError(TRUE),
6667
bufferLength(0),
68+
isBuffer(FALSE),
6769
density(72.0),
6870
rawChannels(0),
6971
rawWidth(0),

0 commit comments

Comments
 (0)