mirror of
https://github.com/lovell/sharp.git
synced 2025-07-12 20:10:13 +02:00
Input image decoding fail fast by default
This commit is contained in:
parent
a183bb1cac
commit
fa69ff773a
@ -9,9 +9,8 @@
|
|||||||
a String containing the path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
|
a String containing the path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
|
||||||
JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
||||||
- `options` **[Object][3]?** if present, is an Object with optional attributes.
|
- `options` **[Object][3]?** if present, is an Object with optional attributes.
|
||||||
- `options.failOnError` **[Boolean][4]** by default apply a "best effort"
|
- `options.failOnError` **[Boolean][4]** by default halt processing and raise an error when loading invalid images.
|
||||||
to decode images, even if the data is corrupt or invalid. Set this flag to true
|
Set this flag to `false` if you'd rather apply a "best effort" to decode images, even if the data is corrupt or invalid. (optional, default `true`)
|
||||||
if you'd rather halt processing and raise an error when loading invalid images. (optional, default `false`)
|
|
||||||
- `options.density` **[Number][5]** number representing the DPI for vector images. (optional, default `72`)
|
- `options.density` **[Number][5]** number representing the DPI for vector images. (optional, default `72`)
|
||||||
- `options.page` **[Number][5]** page number to extract for multi-page input (GIF, TIFF) (optional, default `0`)
|
- `options.page` **[Number][5]** page number to extract for multi-page input (GIF, TIFF) (optional, default `0`)
|
||||||
- `options.raw` **[Object][3]?** describes raw pixel input image data. See `raw()` for pixel ordering.
|
- `options.raw` **[Object][3]?** describes raw pixel input image data. See `raw()` for pixel ordering.
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
|
|
||||||
Requires libvips v8.7.0.
|
Requires libvips v8.7.0.
|
||||||
|
|
||||||
|
#### v0.21.3 - TBD
|
||||||
|
|
||||||
|
* Input image decoding now fails fast, set `failOnError` to change this behaviour.
|
||||||
|
|
||||||
#### v0.21.2 - 13<sup>th</sup> January 2019
|
#### v0.21.2 - 13<sup>th</sup> January 2019
|
||||||
|
|
||||||
* Ensure all metadata is removed from PNG output unless `withMetadata` used.
|
* Ensure all metadata is removed from PNG output unless `withMetadata` used.
|
||||||
|
@ -61,9 +61,8 @@ const debuglog = util.debuglog('sharp');
|
|||||||
* a String containing the path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
|
* a String containing the path to an JPEG, PNG, WebP, GIF, SVG or TIFF image file.
|
||||||
* JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
* JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data can be streamed into the object when not present.
|
||||||
* @param {Object} [options] - if present, is an Object with optional attributes.
|
* @param {Object} [options] - if present, is an Object with optional attributes.
|
||||||
* @param {Boolean} [options.failOnError=false] - by default apply a "best effort"
|
* @param {Boolean} [options.failOnError=true] - by default halt processing and raise an error when loading invalid images.
|
||||||
* to decode images, even if the data is corrupt or invalid. Set this flag to true
|
* Set this flag to `false` if you'd rather apply a "best effort" to decode images, even if the data is corrupt or invalid.
|
||||||
* if you'd rather halt processing and raise an error when loading invalid images.
|
|
||||||
* @param {Number} [options.density=72] - number representing the DPI for vector images.
|
* @param {Number} [options.density=72] - number representing the DPI for vector images.
|
||||||
* @param {Number} [options.page=0] - page number to extract for multi-page input (GIF, TIFF)
|
* @param {Number} [options.page=0] - page number to extract for multi-page input (GIF, TIFF)
|
||||||
* @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
|
* @param {Object} [options.raw] - describes raw pixel input image data. See `raw()` for pixel ordering.
|
||||||
|
@ -9,7 +9,7 @@ const sharp = require('../build/Release/sharp.node');
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
function _createInputDescriptor (input, inputOptions, containerOptions) {
|
function _createInputDescriptor (input, inputOptions, containerOptions) {
|
||||||
const inputDescriptor = { failOnError: false };
|
const inputDescriptor = { failOnError: true };
|
||||||
if (is.string(input)) {
|
if (is.string(input)) {
|
||||||
// filesystem
|
// filesystem
|
||||||
inputDescriptor.file = input;
|
inputDescriptor.file = input;
|
||||||
|
@ -61,7 +61,7 @@ namespace sharp {
|
|||||||
|
|
||||||
InputDescriptor():
|
InputDescriptor():
|
||||||
buffer(nullptr),
|
buffer(nullptr),
|
||||||
failOnError(FALSE),
|
failOnError(TRUE),
|
||||||
bufferLength(0),
|
bufferLength(0),
|
||||||
density(72.0),
|
density(72.0),
|
||||||
rawChannels(0),
|
rawChannels(0),
|
||||||
|
@ -6,10 +6,9 @@ const sharp = require('../../');
|
|||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
describe('failOnError', function () {
|
describe('failOnError', function () {
|
||||||
it('handles truncated JPEG by default', function (done) {
|
it('handles truncated JPEG', function (done) {
|
||||||
sharp(fixtures.inputJpgTruncated)
|
sharp(fixtures.inputJpgTruncated, { failOnError: false })
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
// .toFile(fixtures.expected('truncated.jpg'), done);
|
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
@ -19,10 +18,9 @@ describe('failOnError', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles truncated PNG by default', function (done) {
|
it('handles truncated PNG', function (done) {
|
||||||
sharp(fixtures.inputPngTruncated)
|
sharp(fixtures.inputPngTruncated, { failOnError: false })
|
||||||
.resize(320, 240)
|
.resize(320, 240)
|
||||||
// .toFile(fixtures.expected('truncated.png'), done);
|
|
||||||
.toBuffer(function (err, data, info) {
|
.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
@ -46,8 +44,8 @@ describe('failOnError', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns errors to callback for truncated JPEG when failOnError is set', function (done) {
|
it('returns errors to callback for truncated JPEG', function (done) {
|
||||||
sharp(fixtures.inputJpgTruncated, { failOnError: true }).toBuffer(function (err, data, info) {
|
sharp(fixtures.inputJpgTruncated).toBuffer(function (err, data, info) {
|
||||||
assert.ok(err.message.includes('VipsJpeg: Premature end of JPEG file'), err);
|
assert.ok(err.message.includes('VipsJpeg: Premature end of JPEG file'), err);
|
||||||
assert.strictEqual(data, null);
|
assert.strictEqual(data, null);
|
||||||
assert.strictEqual(info, null);
|
assert.strictEqual(info, null);
|
||||||
@ -55,8 +53,8 @@ describe('failOnError', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns errors to callback for truncated PNG when failOnError is set', function (done) {
|
it('returns errors to callback for truncated PNG', function (done) {
|
||||||
sharp(fixtures.inputPngTruncated, { failOnError: true }).toBuffer(function (err, data, info) {
|
sharp(fixtures.inputPngTruncated).toBuffer(function (err, data, info) {
|
||||||
assert.ok(err.message.includes('vipspng: libpng read error'), err);
|
assert.ok(err.message.includes('vipspng: libpng read error'), err);
|
||||||
assert.strictEqual(data, null);
|
assert.strictEqual(data, null);
|
||||||
assert.strictEqual(info, null);
|
assert.strictEqual(info, null);
|
||||||
@ -64,8 +62,8 @@ describe('failOnError', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rejects promises for truncated JPEG when failOnError is set', function (done) {
|
it('rejects promises for truncated JPEG', function (done) {
|
||||||
sharp(fixtures.inputJpgTruncated, { failOnError: true })
|
sharp(fixtures.inputJpgTruncated)
|
||||||
.toBuffer()
|
.toBuffer()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
throw new Error('Expected rejection');
|
throw new Error('Expected rejection');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user