From 84cab4adfc62a2ffde8416d57ac02bf33705d03e Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Tue, 29 Apr 2014 12:26:28 -0700 Subject: [PATCH] CSS Filter: Bring back the size check. Woops. --- r2/r2/lib/cssfilter.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/r2/r2/lib/cssfilter.py b/r2/r2/lib/cssfilter.py index fb4382b01..c2802445d 100644 --- a/r2/r2/lib/cssfilter.py +++ b/r2/r2/lib/cssfilter.py @@ -316,9 +316,11 @@ ERROR_MESSAGES = { "UNEXPECTED_TOKEN": N_('unexpected token "%(token)s"'), "BACKSLASH": N_("backslashes are not allowed"), "CONTROL_CHARACTER": N_("control characters are not allowed"), + "TOO_BIG": N_("the stylesheet is too big. maximum size: %(size)d KiB"), } +MAX_SIZE_KIB = 100 SUBREDDIT_IMAGE_URL_PLACEHOLDER = re.compile(r"\A%%([a-zA-Z0-9\-]+)%%\Z") @@ -479,6 +481,9 @@ class StylesheetValidator(object): break def parse_and_validate(self, stylesheet_source): + if len(stylesheet_source) > (MAX_SIZE_KIB * 1024): + return "", [ValidationError(0, "TOO_BIG", {"size": MAX_SIZE_KIB})] + nodes = tinycss2.parse_stylesheet(stylesheet_source) source_lines = stylesheet_source.splitlines()