Message decoding exception handler fix

- was unfinished and caused the object processor thread to crash
This commit is contained in:
Peter Šurda 2018-02-13 13:24:37 +01:00
parent 3ad94cb4aa
commit f9a648d720
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
2 changed files with 25 additions and 11 deletions

View File

@ -509,7 +509,10 @@ class objectProcessor(threading.Thread):
if toLabel == '':
toLabel = toAddress
decodedMessage = helper_msgcoding.MsgDecode(messageEncodingType, message)
try:
decodedMessage = helper_msgcoding.MsgDecode(messageEncodingType, message)
except helper_msgcoding.MsgDecodeException:
return
subject = decodedMessage.subject
body = decodedMessage.body
@ -761,7 +764,10 @@ class objectProcessor(threading.Thread):
sendersAddressVersion, sendersStream, calculatedRipe)
logger.debug('fromAddress: ' + fromAddress)
decodedMessage = helper_msgcoding.MsgDecode(messageEncodingType, message)
try:
decodedMessage = helper_msgcoding.MsgDecode(messageEncodingType, message)
except helper_msgcoding.MsgDecodeException:
return
subject = decodedMessage.subject
body = decodedMessage.body

View File

@ -21,7 +21,15 @@ BITMESSAGE_ENCODING_SIMPLE = 2
BITMESSAGE_ENCODING_EXTENDED = 3
class DecompressionSizeException(Exception):
class MsgEncodeException(Exception):
pass
class MsgDecodeException(Exception):
pass
class DecompressionSizeException(MsgDecodeException):
def __init__(self, size):
self.size = size
@ -38,7 +46,7 @@ class MsgEncode(object):
elif self.encoding == BITMESSAGE_ENCODING_TRIVIAL:
self.encodeTrivial(message)
else:
raise ValueError("Unknown encoding %i" % (encoding))
raise MsgEncodeException("Unknown encoding %i" % (encoding))
def encodeExtended(self, message):
try:
@ -46,10 +54,10 @@ class MsgEncode(object):
self.data = zlib.compress(msgpack.dumps(msgObj.encode(message)), 9)
except zlib.error:
logger.error("Error compressing message")
raise
raise MsgEncodeException("Error compressing message")
except msgpack.exceptions.PackException:
logger.error("Error msgpacking message")
raise
raise MsgEncodeException("Error msgpacking message")
self.length = len(self.data)
def encodeSimple(self, message):
@ -85,7 +93,7 @@ class MsgDecode(object):
data = dc.unconsumed_tail
except zlib.error:
logger.error("Error decompressing message")
raise
raise MsgDecodeException("Error decompressing message")
else:
raise DecompressionSizeException(len(tmp))
@ -94,21 +102,21 @@ class MsgDecode(object):
except (msgpack.exceptions.UnpackException,
msgpack.exceptions.ExtraData):
logger.error("Error msgunpacking message")
raise
raise MsgDecodeException("Error msgunpacking message")
try:
msgType = tmp[""]
except KeyError:
logger.error("Message type missing")
raise
raise MsgDecodeException("Message type missing")
msgObj = messagetypes.constructObject(tmp)
if msgObj is None:
raise ValueError("Malformed message")
raise MsgDecodeException("Malformed message")
try:
msgObj.process()
except:
raise ValueError("Malformed message")
raise MsgDecodeException("Malformed message")
if msgType == "message":
self.subject = msgObj.subject
self.body = msgObj.body