fix: Avoid failing on files with aliased mimetypes.

pull/25/head
Raphaël Vinot 2019-03-18 14:55:45 +01:00
parent 0fb7242472
commit e83acd5d00
4 changed files with 24 additions and 8 deletions

View File

@ -21,9 +21,9 @@ addons:
install: install:
# General dependencies # General dependencies
- sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ trusty multiverse" && sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu/ trusty-updates multiverse"
- sudo apt-get update -qq - sudo apt-get update -qq
- sudo apt-get install -y p7zip-rar python-pip - sudo apt-get -y dist-upgrate
- sudo apt-get install -y p7zip-rar
# filecheck.py dependencies # filecheck.py dependencies
- sudo apt-get install libxml2-dev libxslt1-dev - sudo apt-get install libxml2-dev libxslt1-dev
- wget https://didierstevens.com/files/software/pdfid_v0_2_5.zip - wget https://didierstevens.com/files/software/pdfid_v0_2_5.zip

View File

@ -18,6 +18,7 @@ pillow = "*"
olefile = "*" olefile = "*"
oletools = "*" oletools = "*"
officedissector = {editable = true,git = "https://github.com/grierforensics/officedissector.git"} officedissector = {editable = true,git = "https://github.com/grierforensics/officedissector.git"}
kittengroomer = {editable = true,path = "."}
[requires] [requires]
python_version = "3.6" python_version = "3.6"

14
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "07933a9746ecbc04f9f0c39db78c51b6e6f2f2ebc8d10e7ccf67d0c9bbb0317d" "sha256": "ca76d07407e5ed9ca95b7da07b5ef20f0d7c9345b1c35536e896d1a0e8e1787f"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -24,6 +24,10 @@
"index": "pypi", "index": "pypi",
"version": "==2.1.2" "version": "==2.1.2"
}, },
"kittengroomer": {
"editable": true,
"path": "."
},
"lxml": { "lxml": {
"hashes": [ "hashes": [
"sha256:0358b9e9642bc7d39aac5cffe9884a99a5ca68e5e2c1b89e570ed60da9139908", "sha256:0358b9e9642bc7d39aac5cffe9884a99a5ca68e5e2c1b89e570ed60da9139908",
@ -117,6 +121,13 @@
"sha256:f6c5ef0d7480ad048c054c37632c67fca55299990fff127850181659eea33fc3" "sha256:f6c5ef0d7480ad048c054c37632c67fca55299990fff127850181659eea33fc3"
], ],
"version": "==2.3.1" "version": "==2.3.1"
},
"python-magic": {
"hashes": [
"sha256:f2674dcfad52ae6c49d4803fa027809540b130db1dec928cfbb9240316831375",
"sha256:f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5"
],
"version": "==0.4.15"
} }
}, },
"develop": { "develop": {
@ -249,7 +260,6 @@
"sha256:f2674dcfad52ae6c49d4803fa027809540b130db1dec928cfbb9240316831375", "sha256:f2674dcfad52ae6c49d4803fa027809540b130db1dec928cfbb9240316831375",
"sha256:f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5" "sha256:f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5"
], ],
"index": "pypi",
"version": "==0.4.15" "version": "==0.4.15"
}, },
"pyyaml": { "pyyaml": {

View File

@ -184,15 +184,18 @@ class File(FileBase):
self.make_dangerous('File has no extension') self.make_dangerous('File has no extension')
else: else:
if self.extension in Config.override_ext: if self.extension in Config.override_ext:
expected_mimetype = Config.override_ext[self.extension] expected_mimetypes = Config.override_ext[self.extension]
else: else:
expected_mimetype, encoding = mimetypes.guess_type(self.src_path, expected_mimetype, encoding = mimetypes.guess_type(self.src_path,
strict=False) strict=False)
expected_mimetypes = [expected_mimetype]
if expected_mimetype in Config.aliases: if expected_mimetype in Config.aliases:
expected_mimetype = Config.aliases[expected_mimetype] expected_mimetypes.append(Config.aliases[expected_mimetype])
is_known_extension = self.extension in mimetypes.types_map.keys() is_known_extension = self.extension in mimetypes.types_map.keys()
if is_known_extension and expected_mimetype != self.mimetype: if is_known_extension and self.mimetype not in expected_mimetypes:
self.make_dangerous('Mimetype does not match expected mimetype ({}) for this extension'.format(expected_mimetype)) self.make_dangerous('Mimetype does not match expected mimetypes ({}) for this extension'.format(expected_mimetypes))
def _check_mimetype(self): def _check_mimetype(self):
""" """
@ -210,6 +213,8 @@ class File(FileBase):
mimetype = self.mimetype mimetype = self.mimetype
expected_extensions = mimetypes.guess_all_extensions(mimetype, expected_extensions = mimetypes.guess_all_extensions(mimetype,
strict=False) strict=False)
if mimetype in Config.aliases:
expected_extensions += mimetypes.guess_all_extensions(Config.aliases[mimetype], strict=False)
if expected_extensions: if expected_extensions:
if self.has_extension and self.extension not in expected_extensions: if self.has_extension and self.extension not in expected_extensions:
self.make_dangerous('Extension does not match expected extensions ({}) for this mimetype'.format(expected_extensions)) self.make_dangerous('Extension does not match expected extensions ({}) for this mimetype'.format(expected_extensions))