From: Rhys Hiltner Date: Fri, 6 Apr 2018 18:06:03 +0000 (-0700) Subject: html/template: grow srcset buffer in proportion to need X-Git-Tag: go1.11beta1~937 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f4412aee749e9ca50e37427d169ce1a5543d7f6f;p=gostls13.git 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í Reviewed-by: Brad Fitzpatrick Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot --- diff --git a/src/html/template/escape_test.go b/src/html/template/escape_test.go index dd4c53a80d..d5c258ecaa 100644 --- a/src/html/template/escape_test.go +++ b/src/html/template/escape_test.go @@ -656,6 +656,11 @@ func TestEscape(t *testing.T) { // The second URL is also filtered. ``, }, + { + "srcset buffer growth", + ``, + ``, + }, } for _, test := range tests { diff --git a/src/html/template/url.go b/src/html/template/url.go index a5c775c94e..f0516300de 100644 --- a/src/html/template/url.go +++ b/src/html/template/url.go @@ -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