mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
add an infinity-loop detection to block-level parsing
This commit is contained in:
parent
d4c367a949
commit
0c62e28e90
15
block.go
15
block.go
|
@ -31,8 +31,23 @@ func (p *parser) block(out *bytes.Buffer, data []byte) {
|
|||
}
|
||||
p.nesting++
|
||||
|
||||
lastLen := 0
|
||||
sameLenCount := 0
|
||||
|
||||
// parse out one block-level construct at a time
|
||||
for len(data) > 0 {
|
||||
curLen := len(data)
|
||||
if curLen == lastLen {
|
||||
sameLenCount += 1
|
||||
if sameLenCount >= 3 {
|
||||
// infinity loop detection
|
||||
return
|
||||
}
|
||||
} else {
|
||||
sameLenCount = 0
|
||||
}
|
||||
lastLen = curLen
|
||||
|
||||
// prefixed header:
|
||||
//
|
||||
// # Header 1
|
||||
|
|
Loading…
Reference in New Issue
Block a user