Skip to content

Commit

Permalink
fix: check buffer length before type conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
matmen committed Apr 3, 2024
1 parent 9a15f58 commit 577ca48
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ImageScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -1624,31 +1624,31 @@ 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;
}

/**
* @param {DataView} view
* @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;
}

/**
* @param {DataView} view
* @returns {boolean}
*/
static isTIFF(view) {
return view.getUint32(0, false) === MAGIC_NUMBERS.TIFF;
return view.byteLength >= 4 && view.getUint32(0, false) === MAGIC_NUMBERS.TIFF;
}

/**
* @param {DataView} view
* @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;
}
}

Expand Down

0 comments on commit 577ca48

Please sign in to comment.