Detect start of font file

main
Bob Mottram 2020-05-26 20:07:04 +01:00
parent c7c2866220
commit 7cd33447ca
1 changed files with 14 additions and 9 deletions

View File

@ -623,6 +623,7 @@ def saveMediaInFormPOST(mediaBytes, debug: bool,
'OTTO': 'application/x-font-opentype' 'OTTO': 'application/x-font-opentype'
} }
detectedExtension = None detectedExtension = None
isFont = False
for extension, contentType in extensionList.items(): for extension, contentType in extensionList.items():
searchStr = b'Content-Type: ' + contentType.encode('utf8', 'ignore') searchStr = b'Content-Type: ' + contentType.encode('utf8', 'ignore')
mediaLocation = mediaBytes.find(searchStr) mediaLocation = mediaBytes.find(searchStr)
@ -647,20 +648,24 @@ def saveMediaInFormPOST(mediaBytes, debug: bool,
elif extension == 'wOF2': elif extension == 'wOF2':
detectedExtension = 'woff2' detectedExtension = 'woff2'
elif extension == 'OTTO': elif extension == 'OTTO':
detectedExtension = 'otf' detectedExtension = 'otf'
isFont = True
break break
if not filename: if not filename:
return None, None return None, None
# locate the beginning of the image, after any if isFont:
# carriage returns startPos = mediaLocation
startPos = mediaLocation + len(searchStr) else:
for offset in range(1, 8): # locate the beginning of the image, after any
if mediaBytes[startPos+offset] != 10: # carriage returns
if mediaBytes[startPos+offset] != 13: startPos = mediaLocation + len(searchStr)
startPos += offset for offset in range(1, 8):
break if mediaBytes[startPos+offset] != 10:
if mediaBytes[startPos+offset] != 13:
startPos += offset
break
# remove any existing image files with a different format # remove any existing image files with a different format
extensionTypes = ('png', 'jpg', 'jpeg', 'gif', 'webp', extensionTypes = ('png', 'jpg', 'jpeg', 'gif', 'webp',