Skip to content

Commit

Permalink
don't crash even when there is an encoding error in the string
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuhoang committed Dec 10, 2018
1 parent 760770b commit 0396e24
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions bitextor-identifyMIME.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,18 @@
magicoutput[0]=magicoutput[0][:-1]
magicoutput.append(url)
try:
magicoutput.append(base64.b64encode(base64.b64decode(content + "==").decode(magicoutput[1].split("=")[1].replace("unknown-8bit","iso-8859-1").replace('us-ascii','iso-8859-1')).encode("utf8")).decode("utf8"))
print("\t".join(magicoutput))
str = base64.b64encode(base64.b64decode(content + "==").decode(magicoutput[1].split("=")[1].replace("unknown-8bit","iso-8859-1").replace('us-ascii','iso-8859-1')).encode("utf8")).decode("utf8")
magicoutput.append(str)

#sys.stderr.write(str)
except LookupError as e:
sys.stderr.write("Unknown character encoding in file "+url+": "+str(e)+"\n")
sys.stderr.write("Unknown character encoding in file " + url + ": " + str(e) + "\n")

except:
sys.stderr.write("Dunno")
magicoutput.append("ZHVubm8K") # dunno

print("\t".join(magicoutput))

else:
sys.stderr.write("Wrong line: "+line.strip()+"\n")

0 comments on commit 0396e24

Please sign in to comment.