markdown: Increase max rendered message length to 1MB.

This should help with #17425, where messages with lots of LaTeX are
lost, due to the large expansion factor.

This isn't a total fix for this - large messages with lots of LaTeX
can still end up larger than 1MB, and rendering could timeout, but
this fix should help significantly.

1MB is still small enough that I don't expect we'll run into any DOS
problems - my testing didn't show any problems rendering messages that
contain ~1MB of LaTeX.
This commit is contained in:
Wesley Aptekar-Cassels 2021-05-28 11:04:15 -07:00 committed by Tim Abbott
parent b584790541
commit d5ba94082a
2 changed files with 4 additions and 4 deletions

View File

@ -2612,9 +2612,9 @@ def do_convert(
# rest of the codebase from any bugs where we end up rendering # rest of the codebase from any bugs where we end up rendering
# something huge. # something huge.
MAX_MESSAGE_LENGTH = settings.MAX_MESSAGE_LENGTH MAX_MESSAGE_LENGTH = settings.MAX_MESSAGE_LENGTH
if len(rendered_content) > MAX_MESSAGE_LENGTH * 10: if len(rendered_content) > MAX_MESSAGE_LENGTH * 100:
raise MarkdownRenderingException( raise MarkdownRenderingException(
f"Rendered content exceeds {MAX_MESSAGE_LENGTH * 10} characters (message {logging_message_id})" f"Rendered content exceeds {MAX_MESSAGE_LENGTH * 100} characters (message {logging_message_id})"
) )
return rendered_content return rendered_content
except Exception: except Exception:

View File

@ -2749,9 +2749,9 @@ class MarkdownErrorTests(ZulipTestCase):
@override_settings(MAX_MESSAGE_LENGTH=10) @override_settings(MAX_MESSAGE_LENGTH=10)
def test_ultra_long_rendering(self) -> None: def test_ultra_long_rendering(self) -> None:
"""A rendered message with an ultra-long length (> 10 * MAX_MESSAGE_LENGTH) """A rendered message with an ultra-long length (> 100 * MAX_MESSAGE_LENGTH)
throws an exception""" throws an exception"""
msg = "mock rendered message\n" * settings.MAX_MESSAGE_LENGTH msg = "mock rendered message\n" * 10 * settings.MAX_MESSAGE_LENGTH
with mock.patch("zerver.lib.markdown.timeout", return_value=msg), mock.patch( with mock.patch("zerver.lib.markdown.timeout", return_value=msg), mock.patch(
"zerver.lib.markdown.markdown_logger" "zerver.lib.markdown.markdown_logger"