Skip to content
Snippets Groups Projects
Commit c885c24a authored by Chris Lamb's avatar Chris Lamb :eyes:
Browse files

Prevent a traceback when comparing a contentful .pyc file with an empty one. (Re: Debian:#1064973)

They were being detected as PycFiles via FALLBACK_FILE_EXTENSION_SUFFIX,
but this allowed (valid, it seems!) empty .pyc files to be processed by
code that assumed that the file was non-empty. This patch continues
to detect them as PycFiles but does not attempt in-depth parsing.
parent 529d0ae3
No related branches found
No related tags found
No related merge requests found
Pipeline #647049 failed
...@@ -21,6 +21,7 @@ import binascii ...@@ -21,6 +21,7 @@ import binascii
import dis import dis
import io import io
import marshal import marshal
import os
import re import re
import struct import struct
import time import time
...@@ -66,6 +67,12 @@ def describe_pyc(filename): ...@@ -66,6 +67,12 @@ def describe_pyc(filename):
def parse_pyc(f): def parse_pyc(f):
f.seek(0, io.SEEK_END)
if f.tell() == 0:
yield "type: empty"
return
f.seek(0)
magic = f.read(4) magic = f.read(4)
yield "magic: {}".format(hexlify(magic)) yield "magic: {}".format(hexlify(magic))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment