Skip to content

Commit

Permalink
Handle zero-length Buffers in Node.js v13.2.0+
Browse files Browse the repository at this point in the history
These now use nullptr internally - see
nodejs/node#30339
  • Loading branch information
lovell committed Nov 28, 2019
1 parent bb15cd9 commit 400ef71
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace sharp {
v8::Local<v8::Object> buffer = AttrAs<v8::Object>(input, "buffer");
descriptor->bufferLength = node::Buffer::Length(buffer);
descriptor->buffer = node::Buffer::Data(buffer);
descriptor->isBuffer = TRUE;
buffersToPersist.push_back(buffer);
}
descriptor->failOnError = AttrTo<bool>(input, "failOnError");
Expand Down Expand Up @@ -246,7 +247,7 @@ namespace sharp {
std::tuple<VImage, ImageType> 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,
Expand Down
2 changes: 2 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace sharp {
char *buffer;
bool failOnError;
size_t bufferLength;
bool isBuffer;
double density;
int rawChannels;
int rawWidth;
Expand All @@ -64,6 +65,7 @@ namespace sharp {
buffer(nullptr),
failOnError(TRUE),
bufferLength(0),
isBuffer(FALSE),
density(72.0),
rawChannels(0),
rawWidth(0),
Expand Down

0 comments on commit 400ef71

Please sign in to comment.