From 6553f0fe1c948f74b58c5b1559fd04a0aa4fec78 Mon Sep 17 00:00:00 2001 From: Sudhir Balaji Date: Wed, 25 Sep 2024 00:15:31 +0100 Subject: [PATCH 1/2] Match all 8 bytes of PNG signature --- filetype/types/image.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/filetype/types/image.py b/filetype/types/image.py index 783aa7b..be79af7 100644 --- a/filetype/types/image.py +++ b/filetype/types/image.py @@ -133,12 +133,15 @@ def __init__(self): ) def match(self, buf): - return (len(buf) > 3 and + return (len(buf) > 8 and buf[0] == 0x89 and buf[1] == 0x50 and buf[2] == 0x4E and - buf[3] == 0x47) - + buf[3] == 0x47 and + buf[4] == 0x0D and + buf[5] == 0x0A and + buf[6] == 0x1A and + buf[7] == 0x0A) class Gif(Type): """ From e56dacb6e7a30240f90b2a6880123c8c7350bed2 Mon Sep 17 00:00:00 2001 From: Sudhir Balaji Date: Thu, 3 Oct 2024 23:29:40 +0100 Subject: [PATCH 2/2] Refactor byte sequence for APNG matcher --- filetype/types/image.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/filetype/types/image.py b/filetype/types/image.py index be79af7..f814234 100644 --- a/filetype/types/image.py +++ b/filetype/types/image.py @@ -95,8 +95,14 @@ def __init__(self): def match(self, buf): if (len(buf) > 8 and - buf[:8] == bytearray([0x89, 0x50, 0x4e, 0x47, - 0x0d, 0x0a, 0x1a, 0x0a])): + buf[0] == 0x89 and + buf[1] == 0x50 and + buf[2] == 0x4E and + buf[3] == 0x47 and + buf[4] == 0x0D and + buf[5] == 0x0A and + buf[6] == 0x1A and + buf[7] == 0x0A): # cursor in buf, skip already readed 8 bytes i = 8 while len(buf) > i: