add HEIC/HEIF/AVIF MIME detection signatures

- Add ftyp box signatures for heic, mif1, and avif brands
- Add tests for new image formats
- Fix nested if lint warning in lookup rate limit
- Update security docs: MKV uses WebM header, TAR needs offset 257
This commit is contained in:
Username
2025-12-26 17:04:51 +01:00
parent 93a4dd2f97
commit 03bcb157cc
3 changed files with 62 additions and 20 deletions

View File

@@ -124,6 +124,30 @@ class TestMimeDetection:
data = json.loads(response.data)
assert data["mime_type"] == "image/x-icon"
def test_detect_heic(self, client):
"""Detect HEIC from ftyp box with heic brand."""
# ftyp box: size (0x18) + "ftyp" + "heic" brand
heic_header = b"\x00\x00\x00\x18\x66\x74\x79\x70\x68\x65\x69\x63" + b"\x00" * 50
response = client.post("/", data=heic_header)
data = json.loads(response.data)
assert data["mime_type"] == "image/heic"
def test_detect_heif(self, client):
"""Detect HEIF from ftyp box with mif1 brand."""
# ftyp box: size (0x18) + "ftyp" + "mif1" brand
heif_header = b"\x00\x00\x00\x18\x66\x74\x79\x70\x6d\x69\x66\x31" + b"\x00" * 50
response = client.post("/", data=heif_header)
data = json.loads(response.data)
assert data["mime_type"] == "image/heif"
def test_detect_avif(self, client):
"""Detect AVIF from ftyp box with avif brand."""
# ftyp box: size (0x1c) + "ftyp" + "avif" brand
avif_header = b"\x00\x00\x00\x1c\x66\x74\x79\x70\x61\x76\x69\x66" + b"\x00" * 50
response = client.post("/", data=avif_header)
data = json.loads(response.data)
assert data["mime_type"] == "image/avif"
# --- Video Formats ---
def test_detect_webm(self, client):