Skip to content

Commit

Permalink
fixup! fixup! Secure array slicing when expanding macro for stack trace
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrsmk committed Aug 23, 2021
1 parent a7d30df commit 83f5096
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/compiler/crystal/exception.cr
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ module Crystal
source, _ = minimize_indentation(source.lines)
io << Crystal.with_line_numbers(source, line_number, @color)
else
from_index = {0, line_number - MACRO_LINES_TO_SHOW}.max
to_index = {source.lines.size, line_number}.max
to_index = line_number.clamp(0..source.lines.size)
from_index = {0, to_index - MACRO_LINES_TO_SHOW}.max
source_slice = source.lines[from_index...to_index]
source_slice, spaces_removed = minimize_indentation(source_slice)

Expand Down

0 comments on commit 83f5096

Please sign in to comment.