Skip to content

Commit 9be7cee

Browse files
committed
use binaryornot instead of handmade function
Signed-off-by: Pierre Tardy <tardyp@gmail.com>
1 parent 85d15d2 commit 9be7cee

2 files changed

Lines changed: 4 additions & 9 deletions

File tree

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ asgiref==3.2.7
33
attrs==19.3.0
44
backcall==0.1.0
55
beautifulsoup4==4.7.1
6+
binaryornot==0.4.4
67
cached-property==1.5.1
78
cffi==1.14.0
89
contextlib2==0.5.5

vulnerabilities/data_source.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import shutil
2828
import tempfile
2929
import traceback
30+
import xml.etree.ElementTree as ET
31+
from binaryornot.helpers import is_binary_string
3032
from datetime import datetime
3133
from pathlib import Path
3234
from typing import Any
@@ -37,8 +39,6 @@
3739
from typing import Optional
3840
from typing import Set
3941
from typing import Tuple
40-
import xml.etree.ElementTree as ET
41-
4242
from git import Repo, DiffIndex
4343
from packageurl import PackageURL
4444

@@ -332,13 +332,7 @@ def _collect_file_changes(
332332
return added_files, updated_files
333333

334334
def _is_binary(d: DiffIndex):
335-
if not d.b_blob:
336-
return False
337-
try:
338-
d.b_blob.data_stream.read().decode()
339-
except UnicodeDecodeError:
340-
return True
341-
return False
335+
return is_binary_string(d.b_blob.data_stream.read(1024))
342336

343337
for d in cutoff_commit.diff(self._repo.head.commit):
344338
if not _include_file(d.b_path, subdir, recursive, file_ext) or _is_binary(d):

0 commit comments

Comments
 (0)