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)

x86
Windows XP
defect
Not set
critical

Tracking

()

RESOLVED WONTFIX

People

(Reporter: rxpbugzilla, Unassigned)

References

Details

(Keywords: hang, testcase)

Attachments

(3 files, 1 obsolete file)

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
Attached file Testcase —
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
Did that not happen in Gecko 1.8.0.0, say?
Tried Firefox 2.0 and it hangs all the same - so this is not a regression.
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.
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?
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?
Not an exploitable crash, so not blocking on this, but wanted for sure.
Flags: wanted1.9+
Flags: blocking1.9?
Flags: blocking1.9-
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.
So addBinding(this, ...) is bad, but addBinding(somethingElse, ...) is ok?
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.
Attached patch Tracks constructed element (obsolete) — — Splinter Review
Attached patch Stops recursion — — Splinter Review
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.
Blocks: 412767
Attachment #320500 - Attachment is obsolete: true
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.
Keywords: hang, testcase
Severity: normal → critical

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.

Attachment

General

Created:
Updated:
Size: