From a50eddcd947923c3c02efe2c7b5736e4da4df07c Mon Sep 17 00:00:00 2001 From: Martin Srank Date: Thu, 31 Mar 2022 17:14:52 +0200 Subject: [PATCH 1/2] Add support for more WOFF/WOFF2 flavors --- filetype/types/font.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/filetype/types/font.py b/filetype/types/font.py index bdecf39..e46ece9 100644 --- a/filetype/types/font.py +++ b/filetype/types/font.py @@ -19,15 +19,23 @@ def __init__(self): ) def match(self, buf): - return (len(buf) > 7 and + return (len(buf) > 3 and buf[0] == 0x77 and buf[1] == 0x4F and buf[2] == 0x46 and buf[3] == 0x46 and - buf[4] == 0x00 and - buf[5] == 0x01 and - buf[6] == 0x00 and - buf[7] == 0x00) + ((buf[4] == 0x00 and + buf[5] == 0x01 and + buf[6] == 0x00 and + buf[7] == 0x00) or + (buf[4] == 0x4F and + buf[5] == 0x54 and + buf[6] == 0x54 and + buf[7] == 0x4F) or + (buf[4] == 0x74 and + buf[5] == 0x72 and + buf[6] == 0x75 and + buf[7] == 0x65))) class Woff2(Type): @@ -49,10 +57,18 @@ def match(self, buf): buf[1] == 0x4F and buf[2] == 0x46 and buf[3] == 0x32 and - buf[4] == 0x00 and - buf[5] == 0x01 and - buf[6] == 0x00 and - buf[7] == 0x00) + ((buf[4] == 0x00 and + buf[5] == 0x01 and + buf[6] == 0x00 and + buf[7] == 0x00) or + (buf[4] == 0x4F and + buf[5] == 0x54 and + buf[6] == 0x54 and + buf[7] == 0x4F) or + (buf[4] == 0x74 and + buf[5] == 0x72 and + buf[6] == 0x75 and + buf[7] == 0x65))) class Ttf(Type): From 0f76dc5d192d27287ec128e830191b4aabc5c060 Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 19 Apr 2022 22:23:47 +0200 Subject: [PATCH 2/2] fix(font): minimum length check (woff) --- filetype/types/font.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filetype/types/font.py b/filetype/types/font.py index e46ece9..461f5c4 100644 --- a/filetype/types/font.py +++ b/filetype/types/font.py @@ -19,7 +19,7 @@ def __init__(self): ) def match(self, buf): - return (len(buf) > 3 and + return (len(buf) > 7 and buf[0] == 0x77 and buf[1] == 0x4F and buf[2] == 0x46 and