Skip to content

Commit ac00f9b

Browse files
committed
Update pyarchivefile.py
1 parent 507e256 commit ac00f9b

1 file changed

Lines changed: 43 additions & 17 deletions

File tree

pyarchivefile.py

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4232,19 +4232,44 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, uncompress=True, skipcheck
42324232
fjsonchecksumtype = HeaderOut[30]
42334233
fjsonchecksum = HeaderOut[31]
42344234
fjsoncontent = {}
4235-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4236-
if(fjsonsize > 0):
4237-
try:
4238-
fjsoncontent = json.loads(base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8"))
4239-
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4235+
if(fjsontype=="json"):
4236+
fjsoncontent = {}
4237+
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4238+
if(fjsonsize > 0):
42404239
try:
4241-
fjsoncontent = json.loads(fprejsoncontent)
4240+
fjsonrawcontent = base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8")
4241+
fjsoncontent = json.loads(base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8"))
42424242
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4243-
fprejsoncontent = ""
4244-
fjsoncontent = {}
4245-
else:
4246-
fprejsoncontent = ""
4247-
fjsoncontent = {}
4243+
try:
4244+
fjsonrawcontent = fprejsoncontent
4245+
fjsoncontent = json.loads(fprejsoncontent)
4246+
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4247+
fprejsoncontent = ""
4248+
fjsonrawcontent = fprejsoncontent
4249+
fjsoncontent = {}
4250+
else:
4251+
fprejsoncontent = ""
4252+
fjsonrawcontent = fprejsoncontent
4253+
fjsoncontent = {}
4254+
elif(fjsontype=="list"):
4255+
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4256+
flisttmp = MkTempFile()
4257+
flisttmp.write(fprejsoncontent.encode())
4258+
flisttmp.seek(0)
4259+
fjsoncontent = ReadFileHeaderData(flisttmp, fjsonlen, delimiter)
4260+
flisttmp.close()
4261+
fjsonrawcontent = fjsoncontent
4262+
if(fjsonlen==1):
4263+
try:
4264+
fjsonrawcontent = base64.b64decode(fjsoncontent[0]).decode("UTF-8")
4265+
fjsoncontent = json.loads(base64.b64decode(fjsoncontent[0]).decode("UTF-8"))
4266+
fjsonlen = len(fjsoncontent)
4267+
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4268+
try:
4269+
fjsonrawcontent = fjsoncontent[0]
4270+
fjsoncontent = json.loads(fjsoncontent[0])
4271+
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4272+
pass
42484273
fp.seek(len(delimiter), 1)
42494274
jsonfcs = GetFileChecksum(fprejsoncontent, fjsonchecksumtype, True, formatspecs)
42504275
if(jsonfcs != fjsonchecksum and not skipchecksum):
@@ -4765,7 +4790,7 @@ def ReadFileDataWithContentToArray(fp, filestart=0, seekstart=0, seekend=0, list
47654790
fnumextrafieldsize = int(inheader[6], 16)
47664791
fnumextrafields = int(inheader[7], 16)
47674792
fextrafieldslist = []
4768-
extrastart = 7
4793+
extrastart = 8
47694794
extraend = extrastart + fnumextrafields
47704795
while(extrastart < extraend):
47714796
fextrafieldslist.append(inheader[extrastart])
@@ -4918,10 +4943,10 @@ def ReadFileDataWithContentToList(fp, filestart=0, seekstart=0, seekend=0, listo
49184943
else:
49194944
inheader = ReadFileHeaderDataWoSize(
49204945
fp, formatspecs['format_delimiter'])
4921-
fnumextrafieldsize = int(inheader[5], 16)
4922-
fnumextrafields = int(inheader[6], 16)
4946+
fnumextrafieldsize = int(inheader[6], 16)
4947+
fnumextrafields = int(inheader[7], 16)
49234948
fextrafieldslist = []
4924-
extrastart = 7
4949+
extrastart = 8
49254950
extraend = extrastart + fnumextrafields
49264951
while(extrastart < extraend):
49274952
fextrafieldslist.append(inheader[extrastart])
@@ -4940,7 +4965,8 @@ def ReadFileDataWithContentToList(fp, filestart=0, seekstart=0, seekend=0, listo
49404965
fnumfields = int(inheader[1], 16)
49414966
fhencoding = inheader[2]
49424967
fostype = inheader[3]
4943-
fnumfiles = int(inheader[4], 16)
4968+
fpythontype = inheader[4]
4969+
fnumfiles = int(inheader[5], 16)
49444970
fprechecksumtype = inheader[-2]
49454971
fprechecksum = inheader[-1]
49464972
headercheck = ValidateHeaderChecksum([formstring] + inheader[:-1], fprechecksumtype, fprechecksum, formatspecs)
@@ -9411,7 +9437,7 @@ def ArchiveFileValidate(infile, fmttype="auto", filestart=0,
94119437

94129438
fnumextrafieldsize = int(inheader[6], 16)
94139439
fnumextrafields = int(inheader[7], 16)
9414-
extrastart = 7
9440+
extrastart = 8
94159441
extraend = extrastart + fnumextrafields
94169442
formversion = re.findall("([\\d]+)", formstring)
94179443
fheadsize = int(inheader[0], 16)

0 commit comments

Comments
 (0)