fix traceback preventing showing ALT text of an image. Fixes #5247
This commit is contained in:
parent
4db1d2738c
commit
70e145a827
|
@ -483,6 +483,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
def _process_img(self, attrs):
|
def _process_img(self, attrs):
|
||||||
'''Process a img tag.
|
'''Process a img tag.
|
||||||
'''
|
'''
|
||||||
|
mem = ''
|
||||||
try:
|
try:
|
||||||
# Wait maximum 1s for connection
|
# Wait maximum 1s for connection
|
||||||
socket.setdefaulttimeout(1)
|
socket.setdefaulttimeout(1)
|
||||||
|
@ -498,40 +499,38 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
f.fp._sock.fp._sock.settimeout(0.5)
|
f.fp._sock.fp._sock.settimeout(0.5)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
# Max image size = 2 MB (to try to prevent DoS)
|
# Max image size = 2 MB (to try to prevent DoS)
|
||||||
mem = ''
|
deadline = time.time() + 3
|
||||||
deadline = time.time() + 3
|
while True:
|
||||||
while True:
|
if time.time() > deadline:
|
||||||
if time.time() > deadline:
|
gajim.log.debug(str('Timeout loading image %s ' % \
|
||||||
gajim.log.debug(str('Timeout loading image %s ' % \
|
attrs['src'] + ex))
|
||||||
attrs['src'] + ex))
|
mem = ''
|
||||||
mem = ''
|
alt = attrs.get('alt', '')
|
||||||
alt = attrs.get('alt', '')
|
if alt:
|
||||||
if alt:
|
alt += '\n'
|
||||||
alt += '\n'
|
alt += _('Timeout loading image')
|
||||||
alt += _('Timeout loading image')
|
break
|
||||||
break
|
try:
|
||||||
try:
|
temp = f.read(100)
|
||||||
temp = f.read(100)
|
except socket.timeout, ex:
|
||||||
except socket.timeout, ex:
|
gajim.log.debug('Timeout loading image %s ' % attrs['src'] + \
|
||||||
gajim.log.debug('Timeout loading image %s ' % attrs['src'] + \
|
str(ex))
|
||||||
str(ex))
|
alt = attrs.get('alt', '')
|
||||||
mem = ''
|
if alt:
|
||||||
alt = attrs.get('alt', '')
|
alt += '\n'
|
||||||
if alt:
|
alt += _('Timeout loading image')
|
||||||
alt += '\n'
|
break
|
||||||
alt += _('Timeout loading image')
|
if temp:
|
||||||
break
|
mem += temp
|
||||||
if temp:
|
else:
|
||||||
mem += temp
|
break
|
||||||
else:
|
if len(mem) > 2*1024*1024:
|
||||||
break
|
alt = attrs.get('alt', '')
|
||||||
if len(mem) > 2*1024*1024:
|
if alt:
|
||||||
alt = attrs.get('alt', '')
|
alt += '\n'
|
||||||
if alt:
|
alt += _('Image is too big')
|
||||||
alt += '\n'
|
break
|
||||||
alt += _('Image is too big')
|
|
||||||
break
|
|
||||||
pixbuf = None
|
pixbuf = None
|
||||||
if mem:
|
if mem:
|
||||||
# Caveat: GdkPixbuf is known not to be safe to load
|
# Caveat: GdkPixbuf is known not to be safe to load
|
||||||
|
|
Loading…
Reference in New Issue