aboutsummaryrefslogtreecommitdiff
path: root/src/html
diff options
context:
space:
mode:
authorRhys Hiltner <rhys@justin.tv>2018-04-06 11:06:03 -0700
committerBrad Fitzpatrick <bradfitz@golang.org>2018-04-06 18:51:08 +0000
commitf4412aee749e9ca50e37427d169ce1a5543d7f6f (patch)
treee454420109d008c57044812d426eb66c198ef1c8 /src/html
parente13a213c7f9d78cfb79f91bcf9b75e3d22362a92 (diff)
downloadgo-f4412aee749e9ca50e37427d169ce1a5543d7f6f.tar.xz
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>
Diffstat (limited to 'src/html')
-rw-r--r--src/html/template/escape_test.go5
-rw-r--r--src/html/template/url.go2
2 files changed, 6 insertions, 1 deletions
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.
`<img srcset="/not-an-image#,#ZgotmplZ">`,
},
+ {
+ "srcset buffer growth",
+ `<img srcset={{",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"}}>`,
+ `<img srcset=,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,>`,
+ },
}
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