Skip to content

Commit 911d9ed

Browse files
[MOD] XML Scanner, entity expansion: stricter limits
1 parent ff69fb4 commit 911d9ed

7 files changed

Lines changed: 15 additions & 12 deletions

File tree

basex-core/src/main/java/org/basex/build/BuildText.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ public interface BuildText {
8888
/** Scanner error. */
8989
String INVPE = "Parameter reference not allowed here.";
9090
/** Scanner error. */
91-
String RECENT = "Recursive entity definition.";
91+
String ENTITY = "Entities: expansion limit exceeded or recursive definitions found.";
9292

9393
/** DTD whitespace error. */
9494
String WSERROR = "Missing Whitespace.";
9595
/** DTD error. */
9696
String ERRDT = "Error in DTD.";
9797

9898
/** Semicolon. */
99-
byte[] SEMI = token(";");
99+
byte[] SEMI = cpToken(';');
100100
/** CDATA token. */
101101
byte[] CDATA = token("CDATA[");
102102
/** XML document version. */

basex-core/src/main/java/org/basex/build/xml/XMLScanner.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ private void attValue(final int ch) throws IOException {
273273
// verify...
274274
final byte[] r = ref(true);
275275
if(r.length == 1) token.add(r);
276-
else if(!input.add(r, false)) throw error(RECENT);
276+
else if(!input.add(r, false)) throw error(ENTITY);
277277
} else {
278278
token.add(c);
279279
}
@@ -301,7 +301,7 @@ private void content(final int ch) throws IOException {
301301
// scan entity
302302
final byte[] r = ref(true);
303303
if(r.length == 1) token.add(r);
304-
else if(!input.add(r, false)) throw error(RECENT);
304+
else if(!input.add(r, false)) throw error(ENTITY);
305305
} else {
306306
if(c == ']') {
307307
// ']]>' not allowed in content
@@ -565,7 +565,7 @@ private int consume() throws IOException {
565565
final byte[] val = pents.get(key);
566566
if(val == null) throw error(UNKNOWNPE, key);
567567
check(';');
568-
input.add(val, true);
568+
if(!input.add(val, true)) throw error(ENTITY);
569569
} else {
570570
return ch;
571571
}

basex-core/src/main/java/org/basex/gui/dialog/DialogResources.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ final class DialogResources extends BaseXBack {
6262
final GUI gui = dialog.gui();
6363
final Data data = gui.context.data();
6464
final String label = data.meta.name + " (/)";
65-
root = new ResourceRootFolder(token(label), token("/"), tree, data);
65+
root = new ResourceRootFolder(token(label), cpToken('/'), tree, data);
6666
((DefaultTreeModel) tree.getModel()).insertNodeInto(root, rootNode, 0);
6767

6868
filter = new BaseXButton(dialog, FILTER);

basex-core/src/main/java/org/basex/io/in/XMLInput.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class XMLInput extends InputStream {
1919
private int ip;
2020
/** Current line. */
2121
private int line = 1;
22+
/** Entity expansion counter. */
23+
private int exp;
2224

2325
/** Buffer with most recent characters. */
2426
private final int[] last = new int[16];
@@ -80,10 +82,10 @@ public int read() throws IOException {
8082
* @throws IOException I/O exception
8183
*/
8284
public boolean add(final byte[] value, final boolean spaces) throws IOException {
83-
if(spaces) add(new NewlineInput(Token.token(" ")));
85+
if(spaces) add(new NewlineInput(Token.cpToken(' ')));
8486
add(new NewlineInput(value));
85-
if(spaces) add(new NewlineInput(Token.token(" ")));
86-
return ip < 32;
87+
if(spaces) add(new NewlineInput(Token.cpToken(' ')));
88+
return ++exp < 32000 && ip < 32;
8789
}
8890

8991
/**

basex-core/src/main/java/org/basex/io/parse/json/JsonConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public interface JsonConstants {
4242
/** Token: name. */
4343
byte[] NAME = token("name");
4444
/** Token: array value. */
45-
byte[] VALUE = token("_");
45+
byte[] VALUE = cpToken('_');
4646

4747
/** Supported data types. */
4848
byte[][] TYPES = { OBJECT, ARRAY, STRING, NUMBER, BOOLEAN, NULL };

basex-core/src/main/java/org/basex/query/func/fn/FnParseXmlFragment.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ final Item parseXml(final QueryContext qc, final boolean fragment,
100100
}
101101

102102
try {
103-
return new DBNode(intparse ? new XMLParser(io, mopts, true) : Parser.xmlParser(io, mopts));
103+
return new DBNode(intparse ? new XMLParser(io, mopts, fragment) :
104+
Parser.xmlParser(io, mopts));
104105
} catch(final IOException ex) {
105106
final Throwable th = ex.getCause();
106107
final QueryException qe = !(th instanceof ValidationException) ? SAXERR_X.get(info, ex) :

basex-core/src/main/java/org/basex/query/util/format/FormatterDE.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ final class FormatterDE extends Formatter {
6363
/** Token: eine. */
6464
private static final byte[] EINE = token("eine");
6565
/** Token: e. */
66-
private static final byte[] E = token("e");
66+
private static final byte[] E = cpToken('e');
6767
/** Token: hundert. */
6868
private static final byte[] HUNDERT = token("hundert");
6969
/** Token: tausend. */

0 commit comments

Comments
 (0)