Skip to content

Commit

Permalink
Secure array slicing when expanding macro for stack trace (crystal-la…
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrsmk authored Sep 24, 2021
1 parent ae915ae commit cc0b8d1
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/compiler/crystal/exception.cr
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ 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
source_slice = source.lines[from_index...line_number]
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)

io << Crystal.with_line_numbers(source_slice, line_number, @color, line_number_start = from_index + 1)
Expand Down

0 comments on commit cc0b8d1

Please sign in to comment.