Closed
Bug 402201
Opened 19 years ago
Closed 7 years ago
[@nsXBLBinding::GenerateAnonymousContent] Calling document.addBinding from XBL constructor causes stack overflow
Categories
(Core :: XBL, defect)
Tracking
()
RESOLVED
WONTFIX
People
(Reporter: rxpbugzilla, Unassigned)
References
Details
(Keywords: hang, testcase)
Attachments
(3 files, 1 obsolete file)
|
638 bytes,
application/xhtml+xml
|
Details | |
|
5.88 KB,
patch
|
Details | Diff | Splinter Review | |
|
6.38 KB,
patch
|
Details | Diff | Splinter Review |
The testcase calls document.addBinding() from the XBL constructor. This should be a valid way to achieve multiple inheritance in XBL. Instead, we get a crash due to stack overflow in Firefox 2.0.0.9. Minefield 2007110205 nightly hangs instead but I guess the issue there is the same.
Talkback report for Firefox 2.0.0.9: TB37638250K
This shows deep recursion in nsXBLBinding::GenerateAnonymousContent
| Reporter | ||
Comment 1•19 years ago
|
||
| Reporter | ||
Comment 2•19 years ago
|
||
Investigated further and found out that document.addBinding() will rerun XBL constructors - which is why we get into an endless loop here. So the issue here (if any) is the fact that constructors run multiple times.
Severity: critical → normal
Keywords: crash
Comment 3•19 years ago
|
||
Did that not happen in Gecko 1.8.0.0, say?
| Reporter | ||
Comment 4•19 years ago
|
||
Tried Firefox 2.0 and it hangs all the same - so this is not a regression.
Comment 5•19 years ago
|
||
So the obvious options I see here are:
1) Change addBinding to throw if a binding is added to a node while in the ctor
of a binding attached to that node.
2) Remove addBinding altogether, since it's buggy in all sorts of ways.
3) Disallow constructor reentry (would break some uses of addBinding, due to
the ctors not being rerun)
4) Do nothing, tell people to not do this, make sure XBL2 doesn't have this
problem.
I suspect we'll end up defaulting to #4 simply due to the principle of least effort, unless someone thinks this is really serious.
Comment 6•19 years ago
|
||
That said... Can untrusted pages call addBinding? Should they be able to? If they can, then we might need to at least put in _some_ protection for it.
Flags: blocking1.9?
| Reporter | ||
Comment 7•19 years ago
|
||
And Firefox 1.5.0.4 hangs as well - just making sure.
> I suspect we'll end up defaulting to #4 simply due to the principle of least
> effort, unless someone thinks this is really serious.
Just what I thought. Definitely not serious for us, we will simply solve our problem in a different way - though multiple inheritance would have been nice.
> That said... Can untrusted pages call addBinding?
Yes, the testcase runs fine without privileges.
> Should they be able to?
They can use -moz-binding, so why shouldn't they be able to call addBinding?
> If
> they can, then we might need to at least put in _some_ protection for it.
That would be #1 I guess?
Comment 8•19 years ago
|
||
Not an exploitable crash, so not blocking on this, but wanted for sure.
Flags: wanted1.9+
Flags: blocking1.9?
Flags: blocking1.9-
Comment 9•18 years ago
|
||
I'd like to work on this, to implement #1 from comment 5. My (probably naive) approach would be to add a flag (mIsConstructing, or something like that) to nsIDocument. The flag gets set and unset in nsXBLPrototypeBinding::BindingAttached and can be checked in nsDocument::AddBinding.
We want it to be possible to call AddBinding from an XBL ctor. You just shouldn't be able to call it to add a binding to the element to which the XBL is currently being attached. If that makes sense.
I.e. given element A and binding B being attached to A. When Bs ctor is running, it should be able to call AddBinding. But it shouldn't be able to call AddBinding to add a binding to A.
Comment 11•18 years ago
|
||
So addBinding(this, ...) is bad, but addBinding(somethingElse, ...) is ok?
Comment 12•18 years ago
|
||
So code wise, I think that means for
- nsXBLPrototypeBinding::BindingAttached(nsIContent* aBoundElement) and
- nsDocument::AddBinding(nsIDOMElement* aContent, const nsAString& aURI)
aBoundElement and aContent cannot be the same.
Yeah, and you probably need to protect binding A adding binding B which tries to add to the element which A is getting bound to.
Comment 14•18 years ago
|
||
Comment 15•18 years ago
|
||
This takes a different approach, stopping the recursion by preventing AddBinding from adding the same binding to an element.
I'm not sure which approach is better. Tracking the constructed element seems simpler. Stopping the recursion is more general but forces addBinding to perform a time consuming check.
I'm running both through the automated tests, then I'll ask for review.
Comment 16•18 years ago
|
||
Attachment #320500 -
Attachment is obsolete: true
Comment 18•17 years ago
|
||
I guess the crash in Firefox 2 is not relevant anymore, so perhaps the summary should be changed that this is causing a hang in current builds.
Updated•17 years ago
|
Severity: normal → critical
Comment 19•7 years ago
|
||
XBL is now disabled in Firefox (Bug 1583314) and is in the process of being removed from Gecko (Bug 1566221), so closing bugs requesting changes to its implementation as wontfix.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → WONTFIX
You need to log in
before you can comment on or make changes to this bug.
Description
•