From 86f8f3ee6f51ad15990732e877e23bc6fea068d5 Mon Sep 17 00:00:00 2001 From: CatKasha Date: Sun, 13 Oct 2024 18:17:07 +0300 Subject: [PATCH 1/2] mkv/webm cleanup --- filetype/types/video.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/filetype/types/video.py b/filetype/types/video.py index 12672ed..cb5437e 100644 --- a/filetype/types/video.py +++ b/filetype/types/video.py @@ -67,9 +67,12 @@ def __init__(self): ) def match(self, buf): - contains_ebml_element = buf.startswith(b'\x1A\x45\xDF\xA3') - contains_doctype_element = buf.find(b'\x42\x82\x88matroska') > -1 - return contains_ebml_element and contains_doctype_element + if(len(buf) > 5 and + buf[0] == 0x1A and + buf[1] == 0x45 and + buf[2] == 0xDF and + buf[3] == 0xA3): + return buf[5:64].find(b"matroska") > -1 class Webm(Type): @@ -86,9 +89,12 @@ def __init__(self): ) def match(self, buf): - contains_ebml_element = buf.startswith(b'\x1A\x45\xDF\xA3') - contains_doctype_element = buf.find(b'\x42\x82\x84webm') > -1 - return contains_ebml_element and contains_doctype_element + if(len(buf) > 5 and + buf[0] == 0x1A and + buf[1] == 0x45 and + buf[2] == 0xDF and + buf[3] == 0xA3): + return buf[5:64].find(b"webm") > -1 class Mov(IsoBmff): From e3ccf8e77e0c2f13aee083a2cc4d167f227d0221 Mon Sep 17 00:00:00 2001 From: CatKasha Date: Mon, 14 Oct 2024 01:25:50 +0300 Subject: [PATCH 2/2] mkv/webm: use ranges in find method --- filetype/types/video.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/filetype/types/video.py b/filetype/types/video.py index cb5437e..3a324ff 100644 --- a/filetype/types/video.py +++ b/filetype/types/video.py @@ -72,7 +72,7 @@ def match(self, buf): buf[1] == 0x45 and buf[2] == 0xDF and buf[3] == 0xA3): - return buf[5:64].find(b"matroska") > -1 + return buf.find(b"matroska", 5, 64) > -1 class Webm(Type): @@ -94,7 +94,7 @@ def match(self, buf): buf[1] == 0x45 and buf[2] == 0xDF and buf[3] == 0xA3): - return buf[5:64].find(b"webm") > -1 + return buf.find(b"webm", 5, 64) > -1 class Mov(IsoBmff):