correctly detect timeout in XHTML image code, print it, and increase timeout. fixes #3122
This commit is contained in:
		
							parent
							
								
									9c67eb961c
								
							
						
					
					
						commit
						c0cd9912b1
					
				
					 1 changed files with 31 additions and 12 deletions
				
			
		|  | @ -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,18 +703,35 @@ 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 | 						break | ||||||
|  | 					try: | ||||||
| 						temp = f.read(100) | 						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 | ||||||
| 					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 | ||||||
| 
 | 
 | ||||||
|  | 				if mem: | ||||||
| 					# Caveat: GdkPixbuf is known not to be safe to load | 					# Caveat: GdkPixbuf is known not to be safe to load | ||||||
| 					# images from network... this program is now potentially | 					# images from network... this program is now potentially | ||||||
| 					# hackable ;) | 					# hackable ;) | ||||||
|  | @ -722,6 +739,8 @@ class HtmlHandler(xml.sax.handler.ContentHandler): | ||||||
| 					loader.write(mem) | 					loader.write(mem) | ||||||
| 					loader.close() | 					loader.close() | ||||||
| 					pixbuf = loader.get_pixbuf() | 					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: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue