[bb & me] don't block when we get an image
This commit is contained in:
parent
a363e9bd2a
commit
5d2257f4a6
1 changed files with 22 additions and 10 deletions
|
@ -35,6 +35,7 @@ import xml.sax, xml.sax.handler
|
||||||
import re
|
import re
|
||||||
import warnings
|
import warnings
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
import socket
|
||||||
import urllib2
|
import urllib2
|
||||||
import operator
|
import operator
|
||||||
|
|
||||||
|
@ -680,22 +681,33 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
|
||||||
if not self.starting:
|
if not self.starting:
|
||||||
self._jump_line()
|
self._jump_line()
|
||||||
elif name == 'img':
|
elif name == 'img':
|
||||||
|
# Wait maximum 1s for connection
|
||||||
|
socket.setdefaulttimeout(1)
|
||||||
try:
|
try:
|
||||||
# Max image size = 2 MB (to try to prevent DoS)
|
f = urllib2.urlopen(attrs['src'])
|
||||||
mem = urllib2.urlopen(attrs['src']).read(2*1024*1024)
|
|
||||||
# Caveat: GdkPixbuf is known not to be safe to load
|
|
||||||
# images from network... this program is now potentially
|
|
||||||
# hackable ;)
|
|
||||||
loader = gtk.gdk.PixbufLoader()
|
|
||||||
loader.write(mem); loader.close()
|
|
||||||
pixbuf = loader.get_pixbuf()
|
|
||||||
except Exception, ex:
|
except Exception, ex:
|
||||||
gajim.log.debug(str('Error loading image'+ex))
|
gajim.log.debug(str('Error loading image %s ' % attrs['src'] + ex))
|
||||||
pixbuf = None
|
pixbuf = None
|
||||||
alt = attrs.get('alt', 'Broken image')
|
alt = attrs.get('alt', 'Broken image')
|
||||||
try:
|
try:
|
||||||
loader.close()
|
loader.close()
|
||||||
except: pass
|
except:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# Wait 10ms between each byte
|
||||||
|
try:
|
||||||
|
f.fp._sock.fp._sock.settimeout(0.01)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
# Max image size = 2 MB (to try to prevent DoS)
|
||||||
|
mem = f.read(2*1024*1024)
|
||||||
|
# Caveat: GdkPixbuf is known not to be safe to load
|
||||||
|
# images from network... this program is now potentially
|
||||||
|
# hackable ;)
|
||||||
|
loader = gtk.gdk.PixbufLoader()
|
||||||
|
loader.write(mem)
|
||||||
|
loader.close()
|
||||||
|
pixbuf = loader.get_pixbuf()
|
||||||
if pixbuf is not None:
|
if pixbuf is not None:
|
||||||
tags = self._get_style_tags()
|
tags = self._get_style_tags()
|
||||||
if tags:
|
if tags:
|
||||||
|
|
Loading…
Add table
Reference in a new issue