From bc2678dc732f2813584f8d500a2d3f899c136edd Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Tue, 19 Apr 2022 11:26:11 +1000 Subject: [PATCH] new paste: check input length Check the input length, if it's over 64k then this will put up an error page that says "Could not submit your paste because ..." Change-Id: I0ba3efbb33050272543b2f76a1cf0f49df26185c --- lodgeit/controllers/pastes.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lodgeit/controllers/pastes.py b/lodgeit/controllers/pastes.py index 7e0779e..5b551ad 100644 --- a/lodgeit/controllers/pastes.py +++ b/lodgeit/controllers/pastes.py @@ -55,6 +55,14 @@ class PasteController(object): 'CAPTCHA solution was incorrect') show_captcha = True + # NOTE(ianw) 2022-04-19 : this goes into a mysql "text" + # field that is 64k + paste_max = 64 * 1024 + code_len = len(code.encode('utf-8')) + if code_len > paste_max: + error = _('your paste is over the 64k limit (by %d)' % + (code_len - paste_max)) + if code and language and not error: paste = Paste(code, language, parent_id, req.user_hash, 'private' in req.form)