zerobucket 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -30
- package/dist/index.cjs +11 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -3092,14 +3092,16 @@ async function validateImage(data, opts) {
|
|
|
3092
3092
|
if (!width || !height)
|
|
3093
3093
|
throw new CorruptedImageError("Image has no readable dimensions");
|
|
3094
3094
|
try {
|
|
3095
|
-
await
|
|
3095
|
+
await sharp(data, {
|
|
3096
|
+
limitInputPixels: maxPixels,
|
|
3097
|
+
failOn: "error",
|
|
3098
|
+
sequentialRead: true
|
|
3099
|
+
}).extract({ left: 0, top: 0, width: 1, height }).raw().toBuffer();
|
|
3096
3100
|
} catch (exc) {
|
|
3097
3101
|
if (isPixelLimit(exc)) throw new ImageTooLargeError(sizeBytes, maxBytes);
|
|
3098
3102
|
throw new CorruptedImageError(
|
|
3099
|
-
`Image data is truncated or corrupted: ${
|
|
3100
|
-
{
|
|
3101
|
-
cause: exc
|
|
3102
|
-
}
|
|
3103
|
+
`Image data is truncated or corrupted: ${decodeDetail(exc)}`,
|
|
3104
|
+
{ cause: exc }
|
|
3103
3105
|
);
|
|
3104
3106
|
}
|
|
3105
3107
|
return { mimeType: FORMAT_TO_MIME[format], width, height, sizeBytes };
|
|
@@ -3143,6 +3145,10 @@ async function validateHeic(data, {
|
|
|
3143
3145
|
}
|
|
3144
3146
|
return { mimeType: FORMAT_TO_MIME.heic, width, height, sizeBytes };
|
|
3145
3147
|
}
|
|
3148
|
+
function decodeDetail(exc) {
|
|
3149
|
+
const msg3 = errMessage(exc).trim();
|
|
3150
|
+
return /^unknown error$/i.test(msg3) ? "the decoder stopped before the end of the image" : msg3;
|
|
3151
|
+
}
|
|
3146
3152
|
function isPixelLimit(exc) {
|
|
3147
3153
|
return /pixel limit/i.test(errMessage(exc));
|
|
3148
3154
|
}
|