zerobucket 0.9.0 → 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/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 make().stats();
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: ${errMessage(exc)}`,
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
  }