Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Weblate
gajim
Commits
5d2257f4
Commit
5d2257f4
authored
18 years ago
by
Yann Leboulanger
Browse files
Options
Downloads
Patches
Plain Diff
[bb & me] don't block when we get an image
parent
a363e9bd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/htmltextview.py
+21
-9
21 additions, 9 deletions
src/htmltextview.py
with
21 additions
and
9 deletions
src/htmltextview.py
+
21
−
9
View file @
5d2257f4
...
...
@@ -35,6 +35,7 @@ import xml.sax, xml.sax.handler
import
re
import
warnings
from
cStringIO
import
StringIO
import
socket
import
urllib2
import
operator
...
...
@@ -680,22 +681,33 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
if
not
self
.
starting
:
self
.
_jump_line
()
elif
name
==
'
img
'
:
# Wait maximum 1s for connection
socket
.
setdefaulttimeout
(
1
)
try
:
f
=
urllib2
.
urlopen
(
attrs
[
'
src
'
])
except
Exception
,
ex
:
gajim
.
log
.
debug
(
str
(
'
Error loading image %s
'
%
attrs
[
'
src
'
]
+
ex
))
pixbuf
=
None
alt
=
attrs
.
get
(
'
alt
'
,
'
Broken image
'
)
try
:
loader
.
close
()
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
=
urllib2
.
urlopen
(
attrs
[
'
src
'
])
.
read
(
2
*
1024
*
1024
)
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
()
loader
.
write
(
mem
)
loader
.
close
()
pixbuf
=
loader
.
get_pixbuf
()
except
Exception
,
ex
:
gajim
.
log
.
debug
(
str
(
'
Error loading image
'
+
ex
))
pixbuf
=
None
alt
=
attrs
.
get
(
'
alt
'
,
'
Broken image
'
)
try
:
loader
.
close
()
except
:
pass
if
pixbuf
is
not
None
:
tags
=
self
.
_get_style_tags
()
if
tags
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment