correctly detect timeout in XHTML image code, print it, and increase timeout. fixes #3122

This commit is contained in:
Yann Leboulanger 2007-05-01 10:14:59 +00:00
parent 9c67eb961c
commit c0cd9912b1

View file

@ -693,7 +693,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
else: else:
# Wait 10ms between each byte # Wait 10ms between each byte
try: try:
f.fp._sock.fp._sock.settimeout(0.01) f.fp._sock.fp._sock.settimeout(0.1)
except: except:
pass pass
# Max image size = 2 MB (to try to prevent DoS) in Max 3s # Max image size = 2 MB (to try to prevent DoS) in Max 3s
@ -703,25 +703,44 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
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))
pixbuf = None mem = ''
alt = attrs.get('alt', 'Timeout loading image') alt = attrs.get('alt', '')
if alt:
alt += '\n'
alt += _('Timeout loading image')
break
try:
temp = f.read(100)
except socket.timeout, ex:
gajim.log.debug('Timeout loading image %s ' % attrs['src'] + \
str(ex))
mem = ''
alt = attrs.get('alt', '')
if alt:
alt += '\n'
alt += _('Timeout loading image')
break break
temp = f.read(100)
if temp: if temp:
mem += temp mem += temp
else: else:
break break
if len(mem) > 2*1024*1024: if len(mem) > 2*1024*1024:
alt = attrs.get('alt', 'Image is too big') alt = attrs.get('alt', '')
if alt:
alt += '\n'
alt += _('Image is too big')
break break
# Caveat: GdkPixbuf is known not to be safe to load if mem:
# images from network... this program is now potentially # Caveat: GdkPixbuf is known not to be safe to load
# hackable ;) # images from network... this program is now potentially
loader = gtk.gdk.PixbufLoader() # hackable ;)
loader.write(mem) loader = gtk.gdk.PixbufLoader()
loader.close() loader.write(mem)
pixbuf = loader.get_pixbuf() loader.close()
pixbuf = loader.get_pixbuf()
else:
pixbuf = None
if pixbuf is not None: if pixbuf is not None:
tags = self._get_style_tags() tags = self._get_style_tags()
if tags: if tags: