Skip to content

Commit

Permalink
Check if chunk is larger than filesize before writing any data to file
Browse files Browse the repository at this point in the history
  • Loading branch information
superr committed May 22, 2020
1 parent 19a5e38 commit ab9d3a3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions splituapp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def extract(source, flist):
py2 = None
if int(''.join(str(i) for i in sys.version_info[0:2])) < 30:
py2 = 1

with open(source, 'rb') as f:
while True:
i = f.read(bytenum)
Expand Down Expand Up @@ -75,29 +75,30 @@ def extract(source, flist):
try:
with open(outdir+os.sep+filename+'.img', 'wb') as o:
while filesize > 0:
o.write(f.read(chunk))
filesize -= chunk

if chunk > filesize:
chunk = filesize

o.write(f.read(chunk))
filesize -= chunk
except:
print('ERROR: Failed to create '+filename+'.img\n')
return 1

img_files.append(filename)

if os.name != 'nt':
if os.path.isfile('crc'):
print('Calculating crc value for '+filename+'.img ...\n')

crcval = []
if py2:
for i in crcdata:
crcval.append('%02X' % ord(i))
else:
for i in crcdata:
crcval.append('%02X' % i)
crcval = ''.join(crcval)

crcval = ''.join(crcval)
crcact = cmd('./crc output/'+filename+'.img')

if crcval != crcact:
Expand Down

0 comments on commit ab9d3a3

Please sign in to comment.