From 25f5262b6ac2505b8b5b96ff9027e91515b3b1bf Mon Sep 17 00:00:00 2001 From: "Luke I. Wilson" Date: Thu, 1 Apr 2021 16:14:39 -0500 Subject: [PATCH] Rope: fix bug in Slice() causing out-of-bounds access --- ui/buffer/rope.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/buffer/rope.go b/ui/buffer/rope.go index dfd1f97..2b47cba 100644 --- a/ui/buffer/rope.go +++ b/ui/buffer/rope.go @@ -97,11 +97,11 @@ func (b *RopeBuffer) Line(line int) []byte { // inclusive bounds. The returned value may or may not be a copy of the data, // so do not write to it. func (b *RopeBuffer) Slice(startLine, startCol, endLine, endCol int) []byte { - endPos := b.LineColToPos(endLine, endCol)+1 + endPos := b.LineColToPos(endLine, endCol) if length := (*rope.Node)(b).Len(); endPos >= length { endPos = length-1 } - return (*rope.Node)(b).Slice(b.LineColToPos(startLine, startCol), endPos) + return (*rope.Node)(b).Slice(b.LineColToPos(startLine, startCol), endPos+1) } // Bytes returns all of the bytes in the buffer. This function is very likely