Skip to content

Commit b4161f8

Browse files
committed
Bugfix: invalid attribute values gave out-of-bounds
1 parent d0c4cdf commit b4161f8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

html/util.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,22 @@ func EscapeAttrVal(buf *[]byte, orig, b []byte) []byte {
4141
return orig
4242
}
4343

44+
n := len(b) + 2
4445
var quote byte
4546
var escapedQuote []byte
4647
if doubles > singles {
48+
n += singles * 4
4749
quote = '\''
4850
escapedQuote = singleQuoteEntityBytes
4951
} else {
52+
n += doubles * 4
5053
quote = '"'
5154
escapedQuote = doubleQuoteEntityBytes
5255
}
53-
if len(b)+2 > cap(*buf) {
54-
*buf = make([]byte, 0, len(b)+2) // maximum size, not actual size
56+
if n > cap(*buf) {
57+
*buf = make([]byte, 0, n) // maximum size, not actual size
5558
}
56-
t := (*buf)[:len(b)+2] // maximum size, not actual size
59+
t := (*buf)[:n] // maximum size, not actual size
5760
t[0] = quote
5861
j := 1
5962
start := 0

0 commit comments

Comments
 (0)