mirror of
https://github.com/golang/go
synced 2024-11-17 03:04:44 -07:00
html/template: grow srcset buffer in proportion to need
In particular, avoid exponential memory usage from growing it in proportion to its current size. Fixes #24731 Change-Id: I277d2fbac2ef7b00ae4b83d6d1dcd7f2e630a5cd Reviewed-on: https://go-review.googlesource.com/105155 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
e13a213c7f
commit
f4412aee74
@ -656,6 +656,11 @@ func TestEscape(t *testing.T) {
|
||||
// The second URL is also filtered.
|
||||
`<img srcset="/not-an-image#,#ZgotmplZ">`,
|
||||
},
|
||||
{
|
||||
"srcset buffer growth",
|
||||
`<img srcset={{",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"}}>`,
|
||||
`<img srcset=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,>`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
@ -88,7 +88,7 @@ func urlProcessor(norm bool, args ...interface{}) string {
|
||||
// processURLOnto appends a normalized URL corresponding to its input to b
|
||||
// and returns true if the appended content differs from s.
|
||||
func processURLOnto(s string, norm bool, b *bytes.Buffer) bool {
|
||||
b.Grow(b.Cap() + len(s) + 16)
|
||||
b.Grow(len(s) + 16)
|
||||
written := 0
|
||||
// The byte loop below assumes that all URLs use UTF-8 as the
|
||||
// content-encoding. This is similar to the URI to IRI encoding scheme
|
||||
|
Loading…
Reference in New Issue
Block a user