From 5c64008c747a46bb0bcf96043f3265d46880b8af Mon Sep 17 00:00:00 2001 From: Diego Muracciole Date: Sat, 18 Apr 2026 16:40:23 +0200 Subject: [PATCH] refactor: use byte-level PNG magic check in image.js --- lib/image.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/image.js b/lib/image.js index 23af05ba..5b7535c7 100644 --- a/lib/image.js +++ b/lib/image.js @@ -28,7 +28,12 @@ class PDFImage { if (data[0] === 0xff && data[1] === 0xd8) { return new JPEG(data, label); - } else if (data[0] === 0x89 && data.toString('ascii', 1, 4) === 'PNG') { + } else if ( + data[0] === 0x89 && + data[1] === 0x50 && + data[2] === 0x4e && + data[3] === 0x47 + ) { return new PNG(data, label); } else { throw new Error('Unknown image format.');