Skip to content

Commit 4e52dfb

Browse files
authored
refactor: use byte-level PNG magic check in image.js (#1718)
1 parent 804022e commit 4e52dfb

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

lib/image.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ class PDFImage {
2828

2929
if (data[0] === 0xff && data[1] === 0xd8) {
3030
return new JPEG(data, label);
31-
} else if (data[0] === 0x89 && data.toString('ascii', 1, 4) === 'PNG') {
31+
} else if (
32+
data[0] === 0x89 &&
33+
data[1] === 0x50 &&
34+
data[2] === 0x4e &&
35+
data[3] === 0x47
36+
) {
3237
return new PNG(data, label);
3338
} else {
3439
throw new Error('Unknown image format.');

0 commit comments

Comments
 (0)