Bug 555899 - Make the HTML5 parser have a limit of 200 on the stack depth like the old parser. rs=sicking.

This commit is contained in:
Henri Sivonen 2010-03-30 11:21:36 +03:00
parent 282e0eeb8c
commit 63a2095f47
3 changed files with 19 additions and 0 deletions

View File

@ -60,6 +60,8 @@ import org.xml.sax.SAXParseException;
public abstract class TreeBuilder<T> implements TokenHandler,
TreeBuilderState<T> {
public static final int STACK_MAX_DEPTH = 200;
// Start dispatch groups
final static int OTHER = 0;
@ -4176,6 +4178,10 @@ public abstract class TreeBuilder<T> implements TokenHandler,
}
@SuppressWarnings("unchecked") private void push(StackNode<T> node) throws SAXException {
if (currentPtr == TreeBuilder.STACK_MAX_DEPTH) {
warn("Maximum depth for tree builder stack reached. Modifying document.");
pop();
}
currentPtr++;
if (currentPtr == stack.length) {
StackNode<T>[] newStack = new StackNode[stack.length + 64];
@ -4188,6 +4194,10 @@ public abstract class TreeBuilder<T> implements TokenHandler,
}
@SuppressWarnings("unchecked") private void silentPush(StackNode<T> node) throws SAXException {
if (currentPtr == TreeBuilder.STACK_MAX_DEPTH) {
warn("Maximum depth for tree builder stack reached. Modifying document.");
pop();
}
currentPtr++;
if (currentPtr == stack.length) {
StackNode<T>[] newStack = new StackNode[stack.length + 64];

View File

@ -3062,6 +3062,10 @@ nsHtml5TreeBuilder::clearLastListSlot()
void
nsHtml5TreeBuilder::push(nsHtml5StackNode* node)
{
if (currentPtr == NS_HTML5TREE_BUILDER_STACK_MAX_DEPTH) {
pop();
}
currentPtr++;
if (currentPtr == stack.length) {
jArray<nsHtml5StackNode*,PRInt32> newStack = jArray<nsHtml5StackNode*,PRInt32>(stack.length + 64);
@ -3076,6 +3080,10 @@ nsHtml5TreeBuilder::push(nsHtml5StackNode* node)
void
nsHtml5TreeBuilder::silentPush(nsHtml5StackNode* node)
{
if (currentPtr == NS_HTML5TREE_BUILDER_STACK_MAX_DEPTH) {
pop();
}
currentPtr++;
if (currentPtr == stack.length) {
jArray<nsHtml5StackNode*,PRInt32> newStack = jArray<nsHtml5StackNode*,PRInt32>(stack.length + 64);

View File

@ -243,6 +243,7 @@ class nsHtml5TreeBuilder : public nsAHtml5TreeBuilderState
jArray<const char*,PRInt32> nsHtml5TreeBuilder::QUIRKY_PUBLIC_IDS = nsnull;
#endif
#define NS_HTML5TREE_BUILDER_STACK_MAX_DEPTH 200
#define NS_HTML5TREE_BUILDER_OTHER 0
#define NS_HTML5TREE_BUILDER_A 1
#define NS_HTML5TREE_BUILDER_BASE 2