Fix sparse check exception

If a program file is less than 28 bytes,
the checking for sparse header will fire exception,
Since the unpack funciton expect the input data length
to be 28 bytes.

This was accidentally reverted by commit
4d5cb463d2
This commit is contained in:
Keith Mok 2022-02-28 22:00:16 -08:00
parent 312cf3bb99
commit 4b81305948

View file

@ -43,7 +43,10 @@ class QCSparse(metaclass=LogBase):
self.__logger.addHandler(fh) self.__logger.addHandler(fh)
def readheader(self): def readheader(self):
header = unpack("<I4H4I", self.rf.read(0x1C)) buf = self.rf.read(0x1C)
if len(buf) != 28:
return False
header = unpack("<I4H4I", buf)
magic = header[0] magic = header[0]
self.major_version = header[1] self.major_version = header[1]
self.minor_version = header[2] self.minor_version = header[2]