Skip to content

Commit

Permalink
Fix panic in EscapeReader (go-gitea#18820)
Browse files Browse the repository at this point in the history
There is a potential panic due to a mistaken resetting of the length parameter when
multibyte characters go over a read boundary.

Signed-off-by: Andrew Thornton <[email protected]>
  • Loading branch information
zeripath authored Feb 19, 2022
1 parent 931c2f4 commit 4b3ebda
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/charset/escape.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ readingloop:
for err == nil {
n, err = text.Read(buf[readStart:])
bs := buf[:n+readStart]
n = len(bs)
i := 0

for i < len(bs) {
Expand Down
9 changes: 9 additions & 0 deletions modules/charset/escape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,12 @@ func TestEscapeControlReader(t *testing.T) {
})
}
}

func TestEscapeControlReader_panic(t *testing.T) {
bs := make([]byte, 0, 20479)
bs = append(bs, 'A')
for i := 0; i < 6826; i++ {
bs = append(bs, []byte("—")...)
}
_, _ = EscapeControlBytes(bs)
}

0 comments on commit 4b3ebda

Please sign in to comment.