mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Expose underlying error message for invalid input #1505
This commit is contained in:
parent
93ad9d4a4a
commit
9dd6510de6
@ -17,6 +17,9 @@ Requires libvips v8.7.0.
|
|||||||
* Expose `pages` and `pageHeight` metadata for multi-page input images.
|
* Expose `pages` and `pageHeight` metadata for multi-page input images.
|
||||||
[#1205](https://github.com/lovell/sharp/issues/1205)
|
[#1205](https://github.com/lovell/sharp/issues/1205)
|
||||||
|
|
||||||
|
* Expose underlying error message for invalid input.
|
||||||
|
[#1505](https://github.com/lovell/sharp/issues/1505)
|
||||||
|
|
||||||
* Prevent mutatation of options passed to `jpeg`.
|
* Prevent mutatation of options passed to `jpeg`.
|
||||||
[#1516](https://github.com/lovell/sharp/issues/1516)
|
[#1516](https://github.com/lovell/sharp/issues/1516)
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@
|
|||||||
"documentation": "^9.1.1",
|
"documentation": "^9.1.1",
|
||||||
"exif-reader": "^1.0.2",
|
"exif-reader": "^1.0.2",
|
||||||
"icc": "^1.0.0",
|
"icc": "^1.0.0",
|
||||||
"license-checker": "^24.1.0",
|
"license-checker": "^25.0.1",
|
||||||
"mocha": "^5.2.0",
|
"mocha": "^5.2.0",
|
||||||
"mock-fs": "^4.7.0",
|
"mock-fs": "^4.7.0",
|
||||||
"nyc": "^13.1.0",
|
"nyc": "^13.1.0",
|
||||||
|
@ -245,8 +245,8 @@ namespace sharp {
|
|||||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
|
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
|
||||||
SetDensity(image, descriptor->density);
|
SetDensity(image, descriptor->density);
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (vips::VError const &err) {
|
||||||
throw vips::VError("Input buffer has corrupt header");
|
throw vips::VError(std::string("Input buffer has corrupt header: ") + err.what());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw vips::VError("Input buffer contains unsupported image format");
|
throw vips::VError("Input buffer contains unsupported image format");
|
||||||
@ -287,8 +287,8 @@ namespace sharp {
|
|||||||
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
|
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
|
||||||
SetDensity(image, descriptor->density);
|
SetDensity(image, descriptor->density);
|
||||||
}
|
}
|
||||||
} catch (...) {
|
} catch (vips::VError const &err) {
|
||||||
throw vips::VError("Input file has corrupt header");
|
throw vips::VError(std::string("Input file has corrupt header: ") + err.what());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw vips::VError("Input file is missing or of an unsupported image format");
|
throw vips::VError("Input file is missing or of an unsupported image format");
|
||||||
|
1
test/fixtures/index.js
vendored
1
test/fixtures/index.js
vendored
@ -70,6 +70,7 @@ module.exports = {
|
|||||||
inputJpgCenteredImage: getPath('centered_image.jpeg'),
|
inputJpgCenteredImage: getPath('centered_image.jpeg'),
|
||||||
inputJpgRandom: getPath('random.jpg'), // convert -size 200x200 xc: +noise Random random.jpg
|
inputJpgRandom: getPath('random.jpg'), // convert -size 200x200 xc: +noise Random random.jpg
|
||||||
inputJpgThRandom: getPath('thRandom.jpg'), // convert random.jpg -channel G -threshold 5% -separate +channel -negate thRandom.jpg
|
inputJpgThRandom: getPath('thRandom.jpg'), // convert random.jpg -channel G -threshold 5% -separate +channel -negate thRandom.jpg
|
||||||
|
inputJpgLossless: getPath('testimgl.jpg'), // Lossless JPEG from ftp://ftp.fu-berlin.de/unix/X11/graphics/ImageMagick/delegates/ljpeg-6b.tar.gz
|
||||||
|
|
||||||
inputPng: getPath('50020484-00001.png'), // http://c.searspartsdirect.com/lis_png/PLDM/50020484-00001.png
|
inputPng: getPath('50020484-00001.png'), // http://c.searspartsdirect.com/lis_png/PLDM/50020484-00001.png
|
||||||
inputPngWithTransparency: getPath('blackbug.png'), // public domain
|
inputPngWithTransparency: getPath('blackbug.png'), // public domain
|
||||||
|
BIN
test/fixtures/testimgl.jpg
vendored
Normal file
BIN
test/fixtures/testimgl.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
@ -457,6 +457,7 @@ describe('Image metadata', function () {
|
|||||||
sharp(fixtures.inputJpgWithCorruptHeader)
|
sharp(fixtures.inputJpgWithCorruptHeader)
|
||||||
.metadata(function (err) {
|
.metadata(function (err) {
|
||||||
assert.strictEqual(true, !!err);
|
assert.strictEqual(true, !!err);
|
||||||
|
assert.strictEqual(true, /Input file has corrupt header: VipsJpeg: Premature end of JPEG file/.test(err.message));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -465,6 +466,16 @@ describe('Image metadata', function () {
|
|||||||
sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader))
|
sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader))
|
||||||
.metadata(function (err) {
|
.metadata(function (err) {
|
||||||
assert.strictEqual(true, !!err);
|
assert.strictEqual(true, !!err);
|
||||||
|
assert.strictEqual(true, /Input buffer has corrupt header: VipsJpeg: Premature end of JPEG file/.test(err.message));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Unsupported lossless JPEG passes underlying error message', function (done) {
|
||||||
|
sharp(fixtures.inputJpgLossless)
|
||||||
|
.metadata(function (err) {
|
||||||
|
assert.strictEqual(true, !!err);
|
||||||
|
assert.strictEqual(true, /Input file has corrupt header: VipsJpeg: Unsupported JPEG process: SOF type 0xc3/.test(err.message));
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user