Skip to content

Commit

Permalink
Reject files opened in binary mode for file types that should be open…
Browse files Browse the repository at this point in the history
…ed in text
  • Loading branch information
stevenxxiu committed Jan 5, 2020
1 parent e2db5d4 commit 03d9000
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/cfv/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ def do_test_file(self, filename, filecrc):
@staticmethod
def auto_chksumfile_match(file, _autorem=re.compile(r'[0-9a-fA-F]{%d} [ *].' % hexlen)):
line = file.peekline(4096)
if isinstance(line, bytes):
return False
while line:
if line[0] not in ';#':
return _autorem.match(line) is not None
Expand Down Expand Up @@ -835,6 +837,8 @@ class SHA1(FooSum_Base, SHA1_MixIn):
@staticmethod
def auto_chksumfile_match(file, _autorem=re.compile(r'[0-9a-fA-F]{40} [ *].')):
line = file.peekline(4096)
if isinstance(line, bytes):
return False
while line:
if line[0] not in ';#':
return _autorem.match(line) is not None
Expand Down Expand Up @@ -873,6 +877,8 @@ class MD5(FooSum_Base, MD5_MixIn):
@staticmethod
def auto_chksumfile_match(file, _autorem=re.compile(r'[0-9a-fA-F]{32} [ *].')):
line = file.peekline(4096)
if isinstance(line, bytes):
return False
while line:
if line[0] not in ';#':
return _autorem.match(line) is not None
Expand Down Expand Up @@ -903,7 +909,10 @@ class BSDMD5(TextChksumType, MD5_MixIn):

@staticmethod
def auto_chksumfile_match(file, _autorem=re.compile(r'MD5 \(.+\) = [0-9a-fA-F]{32}' + '[\r\n]*$')):
return _autorem.match(file.peekline(4096)) is not None
line = file.peekline(4096)
if isinstance(line, bytes):
return False
return _autorem.match(line) is not None

auto_filename_match = b'^md5$'

Expand Down

0 comments on commit 03d9000

Please sign in to comment.