Catch exception for invalid avatars

This commit is contained in:
Philipp Hörist 2017-10-17 20:36:27 +02:00
parent 0d16ef32e6
commit 3a6e1ac9fc
3 changed files with 19 additions and 3 deletions

View File

@ -30,6 +30,7 @@
import os import os
import base64 import base64
import binascii
import operator import operator
import hashlib import hashlib
@ -445,7 +446,11 @@ class ConnectionVcard:
avatar_sha = None avatar_sha = None
photo_decoded = None photo_decoded = None
else: else:
photo_decoded = base64.b64decode(photo.encode('utf-8')) try:
photo_decoded = base64.b64decode(photo.encode('utf-8'))
except binascii.Error as error:
app.log('avatar').warning('Invalid Avatar: %s', error)
return None, None
avatar_sha = hashlib.sha1(photo_decoded).hexdigest() avatar_sha = hashlib.sha1(photo_decoded).hexdigest()
return avatar_sha, photo_decoded return avatar_sha, photo_decoded

View File

@ -24,6 +24,7 @@
from calendar import timegm from calendar import timegm
import datetime import datetime
import hashlib import hashlib
import binascii
import base64 import base64
import hmac import hmac
import logging import logging
@ -599,7 +600,11 @@ class PubsubAvatarReceivedEvent(nec.NetworkIncomingEvent):
log.warning('Received malformed avatar data via pubsub') log.warning('Received malformed avatar data via pubsub')
log.warning(self.stanza) log.warning(self.stanza)
return return
self.data = base64.b64decode(self.data.encode('utf-8')) try:
self.data = base64.b64decode(self.data.encode('utf-8'))
except binascii.Error as err:
log.warning('Received malformed avatar data via pubsub: %s' % err)
return
return True return True

View File

@ -36,6 +36,7 @@ from gi.repository import GLib
from gi.repository import Gdk from gi.repository import Gdk
from gi.repository import GdkPixbuf from gi.repository import GdkPixbuf
import base64 import base64
import binascii
import time import time
import locale import locale
import os import os
@ -210,7 +211,12 @@ class VcardWindow:
photo_encoded = vcard[i]['BINVAL'] photo_encoded = vcard[i]['BINVAL']
if photo_encoded == '': if photo_encoded == '':
continue continue
photo_decoded = base64.b64decode(photo_encoded.encode('utf-8')) try:
photo_decoded = base64.b64decode(
photo_encoded.encode('utf-8'))
except binascii.Error as error:
app.log('avatar').warning('Invalid Avatar: %s', error)
continue
pixbuf = gtkgui_helpers.get_pixbuf_from_data(photo_decoded) pixbuf = gtkgui_helpers.get_pixbuf_from_data(photo_decoded)
if pixbuf is None: if pixbuf is None:
continue continue