-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/net/html: html.Parse() panics #30600
Comments
I don't think it would be just enough to add check in // pop pops the stack. It will panic if s is empty.
func (s *nodeStack) pop() *Node {
i := len(*s)
if i == 0{
return nil
}
n := (*s)[i-1]
*s = (*s)[:i-1]
return n
} sry writing from phone.... |
I believe there is a reason for In the original code cc @bradfitz |
We don't seem to have a specific owner for (@mikioh is listed as the primary owner for the |
The x/net/html package implements the HTML5 parsing algorithm, which has a very, very detailed specification: https://html.spec.whatwg.org/multipage/syntax.html#tree-construction Please bear this in mind. I'd like to avoid making ad-hoc algorithmic changes if possible. CC'ing @TomAnthony who has also recently made a fix to x/net/html. |
I only have familiarity with aspects of the algorithm, but my understanding is... The I think in this case the the issue is with this part of the spec:
The relevant code is at line 1690: if !p.elementInScope(tableScope, p.tok.DataAtom) {
// Ignore the token.
return true
}
// Close the cell and reprocess.
p.popUntil(tableScope, a.Td, a.Th)
p.clearActiveFormattingElements()
p.im = inRowIM The check in step 2 of the spec is never completed, and in this case would be a failure. Then at step 3 we don't do anything (but we shouldn't be there according to the failure at step 2). My initial idea is that we combine these steps as if !p.elementInScope(tableScope, p.tok.DataAtom) {
// Ignore the token.
return true
}
// Close the cell and reprocess.
if (p.popUntil(tableScope, a.Td, a.Th)) {
p.clearActiveFormattingElements()
}
p.im = inRowIM This passes the case above (and all tests) and produces the same output as both Chrome and Firefox for this snippet. If this looks good I can prepare a PR with this and add a test case. |
I've just come back to this. In the spec there is a similar situation in body insertion mode (see An end tag token whose tag name is one of: "applet", "marquee", "object"):
This is handled in the code at line 1127, with a construct that is the same as my suggestion above: if p.popUntil(defaultScope, p.tok.DataAtom) {
p.clearActiveFormattingElements()
} |
…spec In section 12.2.6.4.15 of the spec, there is a condition that the current node is a td or th element, which is not implemented. This can lead to a panic when the open elements stack is popped whilst empty, as outlined in golang/go#30600. This commit implements that check. Fixes golang/go#30600
…spec In section 12.2.6.4.15 of the spec, there is a condition that the current node is a td or th element, which is not implemented. This can lead to a panic when the open elements stack is popped whilst empty, as outlined in golang/go#30600. This commit implements that check. Fixes golang/go#30600
Change https://golang.org/cl/172377 mentions this issue: |
NOTE: this is a bug found by fuzzing. Main bug to track the fuzzing effort: #27848
I'm using the
x/net
package on commit16b79f2e4e9
, master branch, Fri Mar 1 2019.What did you do?
Parsed an html string with the code below
Got panic with "runtime error: index out of range"
Stack trace:
The
pop
states that it will panic ifs
is empty:So I guess it should be the caller responsibility to check for it:
Proposed fix:
If someone is ok with this I'll send a CL with the fix.
The text was updated successfully, but these errors were encountered: