8133962: More general limits

Reviewed-by: dfuchs, lancea, ahgross
This commit is contained in:
Joe Wang 2015-08-30 23:03:23 -07:00
parent e07007fd51
commit 8960391f05
6 changed files with 20 additions and 14 deletions

View file

@ -331,7 +331,7 @@ public class XML11DocumentScannerImpl
new Object[]{entityName}); new Object[]{entityName});
} }
} }
fEntityManager.startEntity(false, entityName, true); fEntityManager.startEntity(true, entityName, true);
} }
} }
} }

View file

@ -904,7 +904,7 @@ public class XML11EntityScanner
} }
int length = fCurrentEntity.position - offset; int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines; fCurrentEntity.columnNumber += length - newlines;
if (fCurrentEntity.reference) { if (fCurrentEntity.isGE) {
checkLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fCurrentEntity, offset, length); checkLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fCurrentEntity, offset, length);
} }
content.setValues(fCurrentEntity.ch, offset, length); content.setValues(fCurrentEntity.ch, offset, length);
@ -1051,6 +1051,9 @@ public class XML11EntityScanner
} }
int length = fCurrentEntity.position - offset; int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines; fCurrentEntity.columnNumber += length - newlines;
if (fCurrentEntity.isGE) {
checkLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fCurrentEntity, offset, length);
}
content.setValues(fCurrentEntity.ch, offset, length); content.setValues(fCurrentEntity.ch, offset, length);
// return next character // return next character

View file

@ -1110,7 +1110,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
/** /**
* Starts a named entity. * Starts a named entity.
* *
* @param reference flag to indicate whether the entity is an Entity Reference. * @param isGE flag to indicate whether the entity is a General Entity
* @param entityName The name of the entity to start. * @param entityName The name of the entity to start.
* @param literal True if this entity is started within a literal * @param literal True if this entity is started within a literal
* value. * value.
@ -1118,7 +1118,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
* @throws IOException Thrown on i/o error. * @throws IOException Thrown on i/o error.
* @throws XNIException Thrown by entity handler to signal an error. * @throws XNIException Thrown by entity handler to signal an error.
*/ */
public void startEntity(boolean reference, String entityName, boolean literal) public void startEntity(boolean isGE, String entityName, boolean literal)
throws IOException, XNIException { throws IOException, XNIException {
// was entity declared? // was entity declared?
@ -1242,7 +1242,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
} }
// start the entity // start the entity
startEntity(reference, entityName, xmlInputSource, literal, external); startEntity(isGE, entityName, xmlInputSource, literal, external);
} // startEntity(String,boolean) } // startEntity(String,boolean)
@ -1291,7 +1291,7 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
* This method can be used to insert an application defined XML * This method can be used to insert an application defined XML
* entity stream into the parsing stream. * entity stream into the parsing stream.
* *
* @param reference flag to indicate whether the entity is an Entity Reference. * @param isGE flag to indicate whether the entity is a General Entity
* @param name The name of the entity. * @param name The name of the entity.
* @param xmlInputSource The input source of the entity. * @param xmlInputSource The input source of the entity.
* @param literal True if this entity is started within a * @param literal True if this entity is started within a
@ -1301,12 +1301,12 @@ public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
* @throws IOException Thrown on i/o error. * @throws IOException Thrown on i/o error.
* @throws XNIException Thrown by entity handler to signal an error. * @throws XNIException Thrown by entity handler to signal an error.
*/ */
public void startEntity(boolean reference, String name, public void startEntity(boolean isGE, String name,
XMLInputSource xmlInputSource, XMLInputSource xmlInputSource,
boolean literal, boolean isExternal) boolean literal, boolean isExternal)
throws IOException, XNIException { throws IOException, XNIException {
String encoding = setupCurrentEntity(reference, name, xmlInputSource, literal, isExternal); String encoding = setupCurrentEntity(isGE, name, xmlInputSource, literal, isExternal);
//when entity expansion limit is set by the Application, we need to //when entity expansion limit is set by the Application, we need to
//check for the entity expansion limit set by the parser, if number of entity //check for the entity expansion limit set by the parser, if number of entity

View file

@ -1038,7 +1038,7 @@ public class XMLEntityScanner implements XMLLocator {
} }
int length = fCurrentEntity.position - offset; int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines; fCurrentEntity.columnNumber += length - newlines;
if (fCurrentEntity.reference) { if (fCurrentEntity.isGE) {
checkLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fCurrentEntity, offset, length); checkLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fCurrentEntity, offset, length);
} }
@ -1205,6 +1205,9 @@ public class XMLEntityScanner implements XMLLocator {
} }
int length = fCurrentEntity.position - offset; int length = fCurrentEntity.position - offset;
fCurrentEntity.columnNumber += length - newlines; fCurrentEntity.columnNumber += length - newlines;
if (fCurrentEntity.isGE) {
checkLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fCurrentEntity, offset, length);
}
content.setValues(fCurrentEntity.ch, offset, length); content.setValues(fCurrentEntity.ch, offset, length);
// return next character // return next character

View file

@ -946,7 +946,7 @@ public abstract class XMLScanner
new Object[]{entityName}); new Object[]{entityName});
} }
} }
fEntityManager.startEntity(false, entityName, true); fEntityManager.startEntity(true, entityName, true);
} }
} }
} }

View file

@ -344,8 +344,8 @@ public abstract class Entity {
// to know that prolog is read // to know that prolog is read
public boolean xmlDeclChunkRead = false; public boolean xmlDeclChunkRead = false;
// flag to indicate whether the Entity is an Entity Reference // flag to indicate whether the Entity is a General Entity
public boolean reference = false; public boolean isGE = false;
/** returns the name of the current encoding /** returns the name of the current encoding
* @return current encoding name * @return current encoding name
@ -391,11 +391,11 @@ public abstract class Entity {
// //
/** Constructs a scanned entity. */ /** Constructs a scanned entity. */
public ScannedEntity(boolean reference, String name, public ScannedEntity(boolean isGE, String name,
XMLResourceIdentifier entityLocation, XMLResourceIdentifier entityLocation,
InputStream stream, Reader reader, InputStream stream, Reader reader,
String encoding, boolean literal, boolean mayReadChunks, boolean isExternal) { String encoding, boolean literal, boolean mayReadChunks, boolean isExternal) {
this.reference = reference; this.isGE = isGE;
this.name = name ; this.name = name ;
this.entityLocation = entityLocation; this.entityLocation = entityLocation;
this.stream = stream; this.stream = stream;