Skip to content

Commit

Permalink
Limit how far up the stack the formatting adoption agency algorithm w…
Browse files Browse the repository at this point in the history
…ill travel

Fixes jhy#234
  • Loading branch information
jhy committed Dec 26, 2012
1 parent 0e37cba commit 2d56df2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ jsoup changelog
* When cloning an Element, reset the classnames set so as not to hold a pointer to the source's.
<https://github.com/jhy/jsoup/issues/278>

* Limit how far up the stack the formatting adoption agency algorithm will travel, to prevent the chance of a run-away
parse when the HTML stack is hopelessly deep.
<https://github.com/jhy/jsoup/issues/234>

*** Release 1.7.1 [2012-Sep-23]
* Improved parse time, now 2.3x faster than previous release, with lower memory consumption.

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,9 @@ else if (!tb.onStack(formatEl)) {
Element commonAncestor = null;
boolean seenFormattingElement = false;
LinkedList<Element> stack = tb.getStack();
for (int si = 0; si < stack.size(); si++) {
// the spec doesn't limit to < 64, but in degenerate cases (9000+ stack depth) this prevents
// run-aways
for (int si = 0; si < stack.size() && si < 64; si++) {
Element el = stack.get(si);
if (el == formatEl) {
commonAncestor = stack.get(si - 1);
Expand Down

0 comments on commit 2d56df2

Please sign in to comment.