Skip to content

Commit

Permalink
8241078: OOM error parsing HTML with large <pre> Tag text
Browse files Browse the repository at this point in the history
Reviewed-by: serb, aivanov
  • Loading branch information
prsadhuk committed Mar 19, 2020
1 parent 3340e6f commit 7143a9c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1264,8 +1264,8 @@ public ElementSpec(AttributeSet a, short type, char[] txt,
int offs, int len) {
attr = a;
this.type = type;
this.data = txt == null ? null : Arrays.copyOf(txt, txt.length);
this.offs = offs;
this.data = txt == null ? null : Arrays.copyOfRange(txt, offs, offs+len);
this.offs = 0;
this.len = len;
this.direction = OriginateDirection;
}
Expand Down
46 changes: 46 additions & 0 deletions test/jdk/javax/swing/text/html/TestOOMWithLargePreTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/**
* @test
* @bug 8241078
* @summary Tests OOM error parsing HTML with large <pre> Tag text
* @run main/othervm -Xmx64M TestOOMWithLargePreTag
*/
import java.io.StringReader;
import javax.swing.text.html.HTMLEditorKit;

public class TestOOMWithLargePreTag {
public static void main(String[] args) throws Exception {
StringBuilder html = new StringBuilder();
html.append("<html><body><pre>");
for (int i = 0; i < 10_000; i++) {
html.append("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
.append("\n");
}
html.append("</pre></body></html>");

HTMLEditorKit kit = new HTMLEditorKit();
kit.read(new StringReader(html.toString()), kit.createDefaultDocument(), 0);
}
}

0 comments on commit 7143a9c

Please sign in to comment.