Fix render length resource limit so it doesn't multiply nested output

This commit is contained in:
Dylan Thacker-Smith
2020-09-03 11:13:04 -04:00
parent 3b486425b0
commit ae9dbe0ca7
5 changed files with 38 additions and 31 deletions
+4 -10
View File
@@ -155,12 +155,10 @@ module Liquid
end
def render_to_output_buffer(context, output)
context.resource_limits.render_score += @nodelist.length
context.resource_limits.increment_render_score(@nodelist.length)
idx = 0
while (node = @nodelist[idx])
previous_output_size = output.bytesize
if node.instance_of?(String)
output << node
else
@@ -172,7 +170,7 @@ module Liquid
end
idx += 1
raise_if_resource_limits_reached(context, output.bytesize - previous_output_size)
context.resource_limits.check_render_length(output.bytesize)
end
output
@@ -184,17 +182,13 @@ module Liquid
node.render_to_output_buffer(context, output)
rescue UndefinedVariable, UndefinedDropMethod, UndefinedFilter => e
context.handle_error(e, node.line_number)
rescue MemoryError
raise
rescue ::StandardError => e
line_number = node.is_a?(String) ? nil : node.line_number
output << context.handle_error(e, line_number)
end
def raise_if_resource_limits_reached(context, length)
context.resource_limits.render_length += length
return unless context.resource_limits.reached?
raise MemoryError, "Memory limits exceeded"
end
def create_variable(token, parse_context)
token.scan(ContentOfVariable) do |content|
markup = content.first