From 7cd33447cae8bafe66ef914912927f65348512d5 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 26 May 2020 20:07:04 +0100 Subject: [PATCH] Detect start of font file --- content.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/content.py b/content.py index fb9c0c92..0bc894bc 100644 --- a/content.py +++ b/content.py @@ -623,6 +623,7 @@ def saveMediaInFormPOST(mediaBytes, debug: bool, 'OTTO': 'application/x-font-opentype' } detectedExtension = None + isFont = False for extension, contentType in extensionList.items(): searchStr = b'Content-Type: ' + contentType.encode('utf8', 'ignore') mediaLocation = mediaBytes.find(searchStr) @@ -647,20 +648,24 @@ def saveMediaInFormPOST(mediaBytes, debug: bool, elif extension == 'wOF2': detectedExtension = 'woff2' elif extension == 'OTTO': - detectedExtension = 'otf' + detectedExtension = 'otf' + isFont = True break if not filename: return None, None - # locate the beginning of the image, after any - # carriage returns - startPos = mediaLocation + len(searchStr) - for offset in range(1, 8): - if mediaBytes[startPos+offset] != 10: - if mediaBytes[startPos+offset] != 13: - startPos += offset - break + if isFont: + startPos = mediaLocation + else: + # locate the beginning of the image, after any + # carriage returns + startPos = mediaLocation + len(searchStr) + for offset in range(1, 8): + if mediaBytes[startPos+offset] != 10: + if mediaBytes[startPos+offset] != 13: + startPos += offset + break # remove any existing image files with a different format extensionTypes = ('png', 'jpg', 'jpeg', 'gif', 'webp',