Web: Disable the fetch sandbox on Python versions with the _MAXHEADERS fix.

Partial fix to GH-1271.
This commit is contained in:
Valentin Lorentz 2016-11-11 12:12:40 +01:00
parent 0b93ab60a0
commit 9c57199838
1 changed files with 37 additions and 20 deletions

View File

@ -46,9 +46,11 @@ _ = PluginInternationalization('Web')
if minisix.PY3:
from html.parser import HTMLParser
from html.entities import entitydefs
import http.client as http_client
else:
from HTMLParser import HTMLParser
from htmlentitydefs import entitydefs
import httplib as http_client
class Title(utils.web.HtmlToText):
entitydefs = entitydefs.copy()
@ -90,6 +92,21 @@ class DelayedIrc:
assert name not in ('reply', 'error', '_irc', '_msg', '_replies')
return getattr(self._irc, name)
if hasattr(http_client, '_MAXHEADERS'):
def fetch_sandbox(f):
"""Runs a command in a forked process with limited memory resources
to prevent memory bomb caused by specially crafted http responses.
On CPython versions with support for limiting the number of headers,
this is the identity function"""
return f
else:
# For the following CPython versions (as well as the matching Pypy
# versions):
# * 2.6 before 2.6.9
# * 2.7 before 2.7.9
# * 3.2 before 3.2.6
# * 3.3 before 3.3.3
def fetch_sandbox(f):
"""Runs a command in a forked process with limited memory resources
to prevent memory bomb caused by specially crafted http responses."""