Commit c885c24a authored by Chris Lamb's avatar Chris Lamb 👀
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
Loading
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import binascii
import dis
import io
import marshal
import os
import re
import struct
import time
@@ -66,6 +67,12 @@ def describe_pyc(filename):


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)
    yield "magic:    {}".format(hexlify(magic))