Skip to content

Commit 4b3ebda

Browse files
authored
Fix panic in EscapeReader (#18820)
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]>
1 parent 931c2f4 commit 4b3ebda

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

modules/charset/escape.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ readingloop:
7474
for err == nil {
7575
n, err = text.Read(buf[readStart:])
7676
bs := buf[:n+readStart]
77+
n = len(bs)
7778
i := 0
7879

7980
for i < len(bs) {

modules/charset/escape_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,12 @@ func TestEscapeControlReader(t *testing.T) {
200200
})
201201
}
202202
}
203+
204+
func TestEscapeControlReader_panic(t *testing.T) {
205+
bs := make([]byte, 0, 20479)
206+
bs = append(bs, 'A')
207+
for i := 0; i < 6826; i++ {
208+
bs = append(bs, []byte("—")...)
209+
}
210+
_, _ = EscapeControlBytes(bs)
211+
}

0 commit comments

Comments
 (0)