mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-18 06:58:19 +00:00
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 <art27@cantab.net>
This commit is contained in:
parent
931c2f40e7
commit
4b3ebda0e7
|
@ -74,6 +74,7 @@ readingloop:
|
||||||
for err == nil {
|
for err == nil {
|
||||||
n, err = text.Read(buf[readStart:])
|
n, err = text.Read(buf[readStart:])
|
||||||
bs := buf[:n+readStart]
|
bs := buf[:n+readStart]
|
||||||
|
n = len(bs)
|
||||||
i := 0
|
i := 0
|
||||||
|
|
||||||
for i < len(bs) {
|
for i < len(bs) {
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue