diff --git a/ImageScript.js b/ImageScript.js index fc205f5..62197e5 100644 --- a/ImageScript.js +++ b/ImageScript.js @@ -1624,7 +1624,7 @@ class ImageType { * @returns {boolean} */ static isPNG(view) { - return view.getUint32(0, false) === MAGIC_NUMBERS.PNG; + return view.byteLength >= 4 && view.getUint32(0, false) === MAGIC_NUMBERS.PNG; } /** @@ -1632,7 +1632,7 @@ class ImageType { * @returns {boolean} */ static isJPEG(view) { - return (view.getUint32(0, false) >>> 8) === MAGIC_NUMBERS.JPEG; + return view.byteLength >= 4 && (view.getUint32(0, false) >>> 8) === MAGIC_NUMBERS.JPEG; } /** @@ -1640,7 +1640,7 @@ class ImageType { * @returns {boolean} */ static isTIFF(view) { - return view.getUint32(0, false) === MAGIC_NUMBERS.TIFF; + return view.byteLength >= 4 && view.getUint32(0, false) === MAGIC_NUMBERS.TIFF; } /** @@ -1648,7 +1648,7 @@ class ImageType { * @returns {boolean} */ static isGIF(view) { - return (view.getUint32(0, false) >>> 8) === MAGIC_NUMBERS.GIF; + return view.byteLength >= 4 && (view.getUint32(0, false) >>> 8) === MAGIC_NUMBERS.GIF; } }