markdown: Increase rendered_content length limit.

This commit increases the rendered_content limit from 2x to 10x of the
original message length.

Earlier, we had placed a limit of MAX_MESSAGE_LENGTH * 2 for the
rendered content (explained in commit
77addc5456).  That limit was based on
the assumption that in most cases, the rendered content wouldn't cause
a large increase in message length. However, quite prominently in
syntax highlighted codeblocks, that wasn't true and this caused the
limit condition to be hit for long messages composed primarily of code
blocks.

Example: The following message would render close to 10x it's original size.

```py
if:
def:
print("x", var)
x = y
```

Because the syntax highlighted logic is extremely compressible, having
rendered_content reach up to 100KB doesn't create a network
performance problem.
This commit is contained in:
Rohitt Vashishtha 2018-04-13 11:53:21 +05:30 committed by Tim Abbott
parent cc927774af
commit 9e7929417d
2 changed files with 4 additions and 3 deletions

View File

@ -1970,8 +1970,9 @@ def do_convert(content: Text,
# Throw an exception if the content is huge; this protects the
# rest of the codebase from any bugs where we end up rendering
# something huge.
if len(rendered_content) > MAX_MESSAGE_LENGTH * 2:
raise BugdownRenderingException()
if len(rendered_content) > MAX_MESSAGE_LENGTH * 10:
raise BugdownRenderingException('Rendered content exceeds %s characters' %
(MAX_MESSAGE_LENGTH * 10,))
return rendered_content
except Exception:
cleaned = privacy_clean_markdown(content)

View File

@ -1261,7 +1261,7 @@ class BugdownErrorTests(ZulipTestCase):
def test_ultra_long_rendering(self) -> None:
"""A message with an ultra-long rendering throws an exception"""
msg = u'* a\n' * (MAX_MESSAGE_LENGTH // 5) # Rendering is >20K characters
msg = u'* a\n' * MAX_MESSAGE_LENGTH # Rendering is >100K characters
with self.simulated_markdown_failure():
with self.assertRaises(bugdown.BugdownRenderingException):