diff --git a/lib/input.js b/lib/input.js index 21cff583..7364f503 100644 --- a/lib/input.js +++ b/lib/input.js @@ -30,9 +30,15 @@ function _createInputDescriptor (input, inputOptions, containerOptions) { inputDescriptor.file = input; } else if (is.buffer(input)) { // Buffer + if (input.length === 0) { + throw Error('Input Buffer is empty'); + } inputDescriptor.buffer = input; } else if (is.uint8Array(input)) { // Uint8Array or Uint8ClampedArray + if (input.length === 0) { + throw Error('Input Bit Array is empty'); + } inputDescriptor.buffer = Buffer.from(input.buffer); } else if (is.plainObject(input) && !is.defined(inputOptions)) { // Plain Object descriptor, e.g. create diff --git a/package.json b/package.json index fab9a3a8..9ccc3837 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,8 @@ "Christian Flintrup ", "Manan Jadhav ", "Leon Radley ", - "alza54 " + "alza54 ", + "Jacob Smith " ], "scripts": { "install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)", diff --git a/test/unit/io.js b/test/unit/io.js index a3d6c816..b0847fd7 100644 --- a/test/unit/io.js +++ b/test/unit/io.js @@ -335,17 +335,6 @@ describe('Input/output', function () { }); }); - it('Fail when input is empty Buffer', function (done) { - sharp(Buffer.alloc(0)).toBuffer().then(function () { - assert(false); - done(); - }).catch(function (err) { - assert(err instanceof Error); - assert.strictEqual('Input buffer contains unsupported image format', err.message); - done(); - }); - }); - it('Fail when input is invalid Buffer', function (done) { sharp(Buffer.from([0x1, 0x2, 0x3, 0x4])).toBuffer().then(function () { assert(false); diff --git a/test/unit/raw.js b/test/unit/raw.js index f3fb3eb2..b4727b69 100644 --- a/test/unit/raw.js +++ b/test/unit/raw.js @@ -7,6 +7,18 @@ const fixtures = require('../fixtures'); describe('Raw pixel data', function () { describe('Raw pixel input', function () { + it('Empty data', function () { + assert.throws(function () { + sharp(Buffer.from('')); + }, /empty/); + assert.throws(function () { + sharp(new Uint8Array(0)); + }, /empty/); + assert.throws(function () { + sharp(new Uint8ClampedArray(0)); + }, /empty/); + }); + it('Missing options', function () { assert.throws(function () { sharp({ raw: {} });