com.sun.xml.internal.stream.Entity.ScannedEntity Java Examples

The following examples show how to use com.sun.xml.internal.stream.Entity.ScannedEntity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XMLEntityScanner.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks whether the value of the specified Limit exceeds its limit
 *
 * @param limit The Limit to be checked
 * @param entity The current entity
 * @param offset The index of the first byte
 * @param length The length of the entity scanned
 */
protected void checkLimit(Limit limit, ScannedEntity entity, int offset, int length) {
    fLimitAnalyzer.addValue(limit, entity.name, length);
    if (fSecurityManager.isOverLimit(limit, fLimitAnalyzer)) {
        fSecurityManager.debugPrint(fLimitAnalyzer);
        Object[] e = (limit == Limit.ENTITY_REPLACEMENT_LIMIT) ?
                new Object[]{fLimitAnalyzer.getValue(limit),
                    fSecurityManager.getLimit(limit), fSecurityManager.getStateLiteral(limit)} :
                new Object[]{entity.name, fLimitAnalyzer.getValue(limit),
                    fSecurityManager.getLimit(limit), fSecurityManager.getStateLiteral(limit)};
        fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, limit.key(),
                e, XMLErrorReporter.SEVERITY_FATAL_ERROR);
    }
    if (fSecurityManager.isOverLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fLimitAnalyzer)) {
        fSecurityManager.debugPrint(fLimitAnalyzer);
        fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "TotalEntitySizeLimit",
                new Object[]{fLimitAnalyzer.getTotalValue(Limit.TOTAL_ENTITY_SIZE_LIMIT),
            fSecurityManager.getLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT),
            fSecurityManager.getStateLiteral(Limit.TOTAL_ENTITY_SIZE_LIMIT)},
                XMLErrorReporter.SEVERITY_FATAL_ERROR);
    }
}
 
Example #2
Source File: XMLVersionDetector.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void fixupCurrentEntity(XMLEntityManager manager,
            char [] scannedChars, int length) {
    ScannedEntity currentEntity = manager.getCurrentEntity();
    if(currentEntity.count-currentEntity.position+length > currentEntity.ch.length) {
        //resize array; this case is hard to imagine...
        char[] tempCh = currentEntity.ch;
        currentEntity.ch = new char[length+currentEntity.count-currentEntity.position+1];
        System.arraycopy(tempCh, 0, currentEntity.ch, 0, tempCh.length);
    }
    if(currentEntity.position < length) {
        // have to move sensitive stuff out of the way...
        System.arraycopy(currentEntity.ch, currentEntity.position, currentEntity.ch, length, currentEntity.count-currentEntity.position);
        currentEntity.count += length-currentEntity.position;
    } else {
        // have to reintroduce some whitespace so this parses:
        for(int i=length; i<currentEntity.position; i++)
            currentEntity.ch[i]=' ';
    }
    // prepend contents...
    System.arraycopy(scannedChars, 0, currentEntity.ch, 0, length);
    currentEntity.position = 0;
    currentEntity.baseCharOffset = 0;
    currentEntity.startPosition = 0;
    currentEntity.columnNumber = currentEntity.lineNumber = 1;
}
 
Example #3
Source File: XMLVersionDetector.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void fixupCurrentEntity(XMLEntityManager manager,
            char [] scannedChars, int length) {
    ScannedEntity currentEntity = manager.getCurrentEntity();
    if(currentEntity.count-currentEntity.position+length > currentEntity.ch.length) {
        //resize array; this case is hard to imagine...
        char[] tempCh = currentEntity.ch;
        currentEntity.ch = new char[length+currentEntity.count-currentEntity.position+1];
        System.arraycopy(tempCh, 0, currentEntity.ch, 0, tempCh.length);
    }
    if(currentEntity.position < length) {
        // have to move sensitive stuff out of the way...
        System.arraycopy(currentEntity.ch, currentEntity.position, currentEntity.ch, length, currentEntity.count-currentEntity.position);
        currentEntity.count += length-currentEntity.position;
    } else {
        // have to reintroduce some whitespace so this parses:
        for(int i=length; i<currentEntity.position; i++)
            currentEntity.ch[i]=' ';
    }
    // prepend contents...
    System.arraycopy(scannedChars, 0, currentEntity.ch, 0, length);
    currentEntity.position = 0;
    currentEntity.baseCharOffset = 0;
    currentEntity.startPosition = 0;
    currentEntity.columnNumber = currentEntity.lineNumber = 1;
}
 
Example #4
Source File: XMLVersionDetector.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void fixupCurrentEntity(XMLEntityManager manager,
            char [] scannedChars, int length) {
    ScannedEntity currentEntity = manager.getCurrentEntity();
    if(currentEntity.count-currentEntity.position+length > currentEntity.ch.length) {
        //resize array; this case is hard to imagine...
        char[] tempCh = currentEntity.ch;
        currentEntity.ch = new char[length+currentEntity.count-currentEntity.position+1];
        System.arraycopy(tempCh, 0, currentEntity.ch, 0, tempCh.length);
    }
    if(currentEntity.position < length) {
        // have to move sensitive stuff out of the way...
        System.arraycopy(currentEntity.ch, currentEntity.position, currentEntity.ch, length, currentEntity.count-currentEntity.position);
        currentEntity.count += length-currentEntity.position;
    } else {
        // have to reintroduce some whitespace so this parses:
        for(int i=length; i<currentEntity.position; i++)
            currentEntity.ch[i]=' ';
    }
    // prepend contents...
    System.arraycopy(scannedChars, 0, currentEntity.ch, 0, length);
    currentEntity.position = 0;
    currentEntity.baseCharOffset = 0;
    currentEntity.startPosition = 0;
    currentEntity.columnNumber = currentEntity.lineNumber = 1;
}
 
Example #5
Source File: XMLEntityScanner.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks whether the value of the specified Limit exceeds its limit
 *
 * @param limit The Limit to be checked
 * @param entity The current entity
 * @param offset The index of the first byte
 * @param length The length of the entity scanned
 */
protected void checkLimit(Limit limit, ScannedEntity entity, int offset, int length) {
    fLimitAnalyzer.addValue(limit, entity.name, length);
    if (fSecurityManager.isOverLimit(limit, fLimitAnalyzer)) {
        fSecurityManager.debugPrint(fLimitAnalyzer);
        Object[] e = (limit == Limit.ENTITY_REPLACEMENT_LIMIT) ?
                new Object[]{fLimitAnalyzer.getValue(limit),
                    fSecurityManager.getLimit(limit), fSecurityManager.getStateLiteral(limit)} :
                new Object[]{entity.name, fLimitAnalyzer.getValue(limit),
                    fSecurityManager.getLimit(limit), fSecurityManager.getStateLiteral(limit)};
        fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, limit.key(),
                e, XMLErrorReporter.SEVERITY_FATAL_ERROR);
    }
    if (fSecurityManager.isOverLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fLimitAnalyzer)) {
        fSecurityManager.debugPrint(fLimitAnalyzer);
        fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "TotalEntitySizeLimit",
                new Object[]{fLimitAnalyzer.getTotalValue(Limit.TOTAL_ENTITY_SIZE_LIMIT),
            fSecurityManager.getLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT),
            fSecurityManager.getStateLiteral(Limit.TOTAL_ENTITY_SIZE_LIMIT)},
                XMLErrorReporter.SEVERITY_FATAL_ERROR);
    }
}
 
Example #6
Source File: XMLVersionDetector.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void fixupCurrentEntity(XMLEntityManager manager,
            char [] scannedChars, int length) {
    ScannedEntity currentEntity = manager.getCurrentEntity();
    if(currentEntity.count-currentEntity.position+length > currentEntity.ch.length) {
        //resize array; this case is hard to imagine...
        char[] tempCh = currentEntity.ch;
        currentEntity.ch = new char[length+currentEntity.count-currentEntity.position+1];
        System.arraycopy(tempCh, 0, currentEntity.ch, 0, tempCh.length);
    }
    if(currentEntity.position < length) {
        // have to move sensitive stuff out of the way...
        System.arraycopy(currentEntity.ch, currentEntity.position, currentEntity.ch, length, currentEntity.count-currentEntity.position);
        currentEntity.count += length-currentEntity.position;
    } else {
        // have to reintroduce some whitespace so this parses:
        for(int i=length; i<currentEntity.position; i++)
            currentEntity.ch[i]=' ';
    }
    // prepend contents...
    System.arraycopy(scannedChars, 0, currentEntity.ch, 0, length);
    currentEntity.position = 0;
    currentEntity.baseCharOffset = 0;
    currentEntity.startPosition = 0;
    currentEntity.columnNumber = currentEntity.lineNumber = 1;
}
 
Example #7
Source File: XMLEntityScanner.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether the value of the specified Limit exceeds its limit
 *
 * @param limit The Limit to be checked
 * @param entity The current entity
 * @param offset The index of the first byte
 * @param length The length of the entity scanned
 */
protected void checkLimit(Limit limit, ScannedEntity entity, int offset, int length) {
    fLimitAnalyzer.addValue(limit, entity.name, length);
    if (fSecurityManager.isOverLimit(limit, fLimitAnalyzer)) {
        fSecurityManager.debugPrint(fLimitAnalyzer);
        Object[] e = (limit == Limit.ENTITY_REPLACEMENT_LIMIT) ?
                new Object[]{fLimitAnalyzer.getValue(limit),
                    fSecurityManager.getLimit(limit), fSecurityManager.getStateLiteral(limit)} :
                new Object[]{entity.name, fLimitAnalyzer.getValue(limit),
                    fSecurityManager.getLimit(limit), fSecurityManager.getStateLiteral(limit)};
        fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, limit.key(),
                e, XMLErrorReporter.SEVERITY_FATAL_ERROR);
    }
    if (fSecurityManager.isOverLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fLimitAnalyzer)) {
        fSecurityManager.debugPrint(fLimitAnalyzer);
        fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "TotalEntitySizeLimit",
                new Object[]{fLimitAnalyzer.getTotalValue(Limit.TOTAL_ENTITY_SIZE_LIMIT),
            fSecurityManager.getLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT),
            fSecurityManager.getStateLiteral(Limit.TOTAL_ENTITY_SIZE_LIMIT)},
                XMLErrorReporter.SEVERITY_FATAL_ERROR);
    }
}
 
Example #8
Source File: XMLVersionDetector.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private void fixupCurrentEntity(XMLEntityManager manager,
            char [] scannedChars, int length) {
    ScannedEntity currentEntity = manager.getCurrentEntity();
    if(currentEntity.count-currentEntity.position+length > currentEntity.ch.length) {
        //resize array; this case is hard to imagine...
        char[] tempCh = currentEntity.ch;
        currentEntity.ch = new char[length+currentEntity.count-currentEntity.position+1];
        System.arraycopy(tempCh, 0, currentEntity.ch, 0, tempCh.length);
    }
    if(currentEntity.position < length) {
        // have to move sensitive stuff out of the way...
        System.arraycopy(currentEntity.ch, currentEntity.position, currentEntity.ch, length, currentEntity.count-currentEntity.position);
        currentEntity.count += length-currentEntity.position;
    } else {
        // have to reintroduce some whitespace so this parses:
        for(int i=length; i<currentEntity.position; i++)
            currentEntity.ch[i]=' ';
    }
    // prepend contents...
    System.arraycopy(scannedChars, 0, currentEntity.ch, 0, length);
    currentEntity.position = 0;
    currentEntity.baseCharOffset = 0;
    currentEntity.startPosition = 0;
    currentEntity.columnNumber = currentEntity.lineNumber = 1;
}
 
Example #9
Source File: XMLEntityScanner.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks whether the value of the specified Limit exceeds its limit
 *
 * @param limit The Limit to be checked
 * @param entity The current entity
 * @param offset The index of the first byte
 * @param length The length of the entity scanned
 */
protected void checkLimit(Limit limit, ScannedEntity entity, int offset, int length) {
    fLimitAnalyzer.addValue(limit, entity.name, length);
    if (fSecurityManager.isOverLimit(limit, fLimitAnalyzer)) {
        fSecurityManager.debugPrint(fLimitAnalyzer);
        Object[] e = (limit == Limit.ENTITY_REPLACEMENT_LIMIT) ?
                new Object[]{fLimitAnalyzer.getValue(limit),
                    fSecurityManager.getLimit(limit), fSecurityManager.getStateLiteral(limit)} :
                new Object[]{entity.name, fLimitAnalyzer.getValue(limit),
                    fSecurityManager.getLimit(limit), fSecurityManager.getStateLiteral(limit)};
        fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, limit.key(),
                e, XMLErrorReporter.SEVERITY_FATAL_ERROR);
    }
    if (fSecurityManager.isOverLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fLimitAnalyzer)) {
        fSecurityManager.debugPrint(fLimitAnalyzer);
        fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "TotalEntitySizeLimit",
                new Object[]{fLimitAnalyzer.getTotalValue(Limit.TOTAL_ENTITY_SIZE_LIMIT),
            fSecurityManager.getLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT),
            fSecurityManager.getStateLiteral(Limit.TOTAL_ENTITY_SIZE_LIMIT)},
                XMLErrorReporter.SEVERITY_FATAL_ERROR);
    }
}
 
Example #10
Source File: XMLVersionDetector.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void fixupCurrentEntity(XMLEntityManager manager,
            char [] scannedChars, int length) {
    ScannedEntity currentEntity = manager.getCurrentEntity();
    if(currentEntity.count-currentEntity.position+length > currentEntity.ch.length) {
        //resize array; this case is hard to imagine...
        char[] tempCh = currentEntity.ch;
        currentEntity.ch = new char[length+currentEntity.count-currentEntity.position+1];
        System.arraycopy(tempCh, 0, currentEntity.ch, 0, tempCh.length);
    }
    if(currentEntity.position < length) {
        // have to move sensitive stuff out of the way...
        System.arraycopy(currentEntity.ch, currentEntity.position, currentEntity.ch, length, currentEntity.count-currentEntity.position);
        currentEntity.count += length-currentEntity.position;
    } else {
        // have to reintroduce some whitespace so this parses:
        for(int i=length; i<currentEntity.position; i++)
            currentEntity.ch[i]=' ';
    }
    // prepend contents...
    System.arraycopy(scannedChars, 0, currentEntity.ch, 0, length);
    currentEntity.position = 0;
    currentEntity.baseCharOffset = 0;
    currentEntity.startPosition = 0;
    currentEntity.columnNumber = currentEntity.lineNumber = 1;
}
 
Example #11
Source File: XMLVersionDetector.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private void fixupCurrentEntity(XMLEntityManager manager,
            char [] scannedChars, int length) {
    ScannedEntity currentEntity = manager.getCurrentEntity();
    if(currentEntity.count-currentEntity.position+length > currentEntity.ch.length) {
        //resize array; this case is hard to imagine...
        char[] tempCh = currentEntity.ch;
        currentEntity.ch = new char[length+currentEntity.count-currentEntity.position+1];
        System.arraycopy(tempCh, 0, currentEntity.ch, 0, tempCh.length);
    }
    if(currentEntity.position < length) {
        // have to move sensitive stuff out of the way...
        System.arraycopy(currentEntity.ch, currentEntity.position, currentEntity.ch, length, currentEntity.count-currentEntity.position);
        currentEntity.count += length-currentEntity.position;
    } else {
        // have to reintroduce some whitespace so this parses:
        for(int i=length; i<currentEntity.position; i++)
            currentEntity.ch[i]=' ';
    }
    // prepend contents...
    System.arraycopy(scannedChars, 0, currentEntity.ch, 0, length);
    currentEntity.position = 0;
    currentEntity.baseCharOffset = 0;
    currentEntity.startPosition = 0;
    currentEntity.columnNumber = currentEntity.lineNumber = 1;
}
 
Example #12
Source File: XMLVersionDetector.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void fixupCurrentEntity(XMLEntityManager manager,
            char [] scannedChars, int length) {
    ScannedEntity currentEntity = manager.getCurrentEntity();
    if(currentEntity.count-currentEntity.position+length > currentEntity.ch.length) {
        //resize array; this case is hard to imagine...
        char[] tempCh = currentEntity.ch;
        currentEntity.ch = new char[length+currentEntity.count-currentEntity.position+1];
        System.arraycopy(tempCh, 0, currentEntity.ch, 0, tempCh.length);
    }
    if(currentEntity.position < length) {
        // have to move sensitive stuff out of the way...
        System.arraycopy(currentEntity.ch, currentEntity.position, currentEntity.ch, length, currentEntity.count-currentEntity.position);
        currentEntity.count += length-currentEntity.position;
    } else {
        // have to reintroduce some whitespace so this parses:
        for(int i=length; i<currentEntity.position; i++)
            currentEntity.ch[i]=' ';
    }
    // prepend contents...
    System.arraycopy(scannedChars, 0, currentEntity.ch, 0, length);
    currentEntity.position = 0;
    currentEntity.baseCharOffset = 0;
    currentEntity.startPosition = 0;
    currentEntity.columnNumber = currentEntity.lineNumber = 1;
}
 
Example #13
Source File: XMLEntityScanner.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Checks whether the value of the specified Limit exceeds its limit
 *
 * @param limit The Limit to be checked
 * @param entity The current entity
 * @param offset The index of the first byte
 * @param length The length of the entity scanned
 */
protected void checkLimit(Limit limit, ScannedEntity entity, int offset, int length) {
    fLimitAnalyzer.addValue(limit, entity.name, length);
    if (fSecurityManager.isOverLimit(limit, fLimitAnalyzer)) {
        fSecurityManager.debugPrint(fLimitAnalyzer);
        Object[] e = (limit == Limit.ENTITY_REPLACEMENT_LIMIT) ?
                new Object[]{fLimitAnalyzer.getValue(limit),
                    fSecurityManager.getLimit(limit), fSecurityManager.getStateLiteral(limit)} :
                new Object[]{entity.name, fLimitAnalyzer.getValue(limit),
                    fSecurityManager.getLimit(limit), fSecurityManager.getStateLiteral(limit)};
        fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, limit.key(),
                e, XMLErrorReporter.SEVERITY_FATAL_ERROR);
    }
    if (fSecurityManager.isOverLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fLimitAnalyzer)) {
        fSecurityManager.debugPrint(fLimitAnalyzer);
        fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "TotalEntitySizeLimit",
                new Object[]{fLimitAnalyzer.getTotalValue(Limit.TOTAL_ENTITY_SIZE_LIMIT),
            fSecurityManager.getLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT),
            fSecurityManager.getStateLiteral(Limit.TOTAL_ENTITY_SIZE_LIMIT)},
                XMLErrorReporter.SEVERITY_FATAL_ERROR);
    }
}
 
Example #14
Source File: XMLVersionDetector.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private void fixupCurrentEntity(XMLEntityManager manager,
            char [] scannedChars, int length) {
    ScannedEntity currentEntity = manager.getCurrentEntity();
    if(currentEntity.count-currentEntity.position+length > currentEntity.ch.length) {
        //resize array; this case is hard to imagine...
        char[] tempCh = currentEntity.ch;
        currentEntity.ch = new char[length+currentEntity.count-currentEntity.position+1];
        System.arraycopy(tempCh, 0, currentEntity.ch, 0, tempCh.length);
    }
    if(currentEntity.position < length) {
        // have to move sensitive stuff out of the way...
        System.arraycopy(currentEntity.ch, currentEntity.position, currentEntity.ch, length, currentEntity.count-currentEntity.position);
        currentEntity.count += length-currentEntity.position;
    } else {
        // have to reintroduce some whitespace so this parses:
        for(int i=length; i<currentEntity.position; i++)
            currentEntity.ch[i]=' ';
    }
    // prepend contents...
    System.arraycopy(scannedChars, 0, currentEntity.ch, 0, length);
    currentEntity.position = 0;
    currentEntity.baseCharOffset = 0;
    currentEntity.startPosition = 0;
    currentEntity.columnNumber = currentEntity.lineNumber = 1;
}
 
Example #15
Source File: XMLEntityScanner.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks whether the value of the specified Limit exceeds its limit
 *
 * @param limit The Limit to be checked
 * @param entity The current entity
 * @param offset The index of the first byte
 * @param length The length of the entity scanned
 */
protected void checkLimit(Limit limit, ScannedEntity entity, int offset, int length) {
    fLimitAnalyzer.addValue(limit, entity.name, length);
    if (fSecurityManager.isOverLimit(limit, fLimitAnalyzer)) {
        fSecurityManager.debugPrint(fLimitAnalyzer);
        Object[] e = (limit == Limit.ENTITY_REPLACEMENT_LIMIT) ?
                new Object[]{fLimitAnalyzer.getValue(limit),
                    fSecurityManager.getLimit(limit), fSecurityManager.getStateLiteral(limit)} :
                new Object[]{entity.name, fLimitAnalyzer.getValue(limit),
                    fSecurityManager.getLimit(limit), fSecurityManager.getStateLiteral(limit)};
        fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, limit.key(),
                e, XMLErrorReporter.SEVERITY_FATAL_ERROR);
    }
    if (fSecurityManager.isOverLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fLimitAnalyzer)) {
        fSecurityManager.debugPrint(fLimitAnalyzer);
        fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "TotalEntitySizeLimit",
                new Object[]{fLimitAnalyzer.getTotalValue(Limit.TOTAL_ENTITY_SIZE_LIMIT),
            fSecurityManager.getLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT),
            fSecurityManager.getStateLiteral(Limit.TOTAL_ENTITY_SIZE_LIMIT)},
                XMLErrorReporter.SEVERITY_FATAL_ERROR);
    }
}
 
Example #16
Source File: XMLVersionDetector.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void fixupCurrentEntity(XMLEntityManager manager,
            char [] scannedChars, int length) {
    ScannedEntity currentEntity = manager.getCurrentEntity();
    if(currentEntity.count-currentEntity.position+length > currentEntity.ch.length) {
        //resize array; this case is hard to imagine...
        char[] tempCh = currentEntity.ch;
        currentEntity.ch = new char[length+currentEntity.count-currentEntity.position+1];
        System.arraycopy(tempCh, 0, currentEntity.ch, 0, tempCh.length);
    }
    if(currentEntity.position < length) {
        // have to move sensitive stuff out of the way...
        System.arraycopy(currentEntity.ch, currentEntity.position, currentEntity.ch, length, currentEntity.count-currentEntity.position);
        currentEntity.count += length-currentEntity.position;
    } else {
        // have to reintroduce some whitespace so this parses:
        for(int i=length; i<currentEntity.position; i++)
            currentEntity.ch[i]=' ';
    }
    // prepend contents...
    System.arraycopy(scannedChars, 0, currentEntity.ch, 0, length);
    currentEntity.position = 0;
    currentEntity.baseCharOffset = 0;
    currentEntity.startPosition = 0;
    currentEntity.columnNumber = currentEntity.lineNumber = 1;
}
 
Example #17
Source File: XMLVersionDetector.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void fixupCurrentEntity(XMLEntityManager manager,
            char [] scannedChars, int length) {
    ScannedEntity currentEntity = manager.getCurrentEntity();
    if(currentEntity.count-currentEntity.position+length > currentEntity.ch.length) {
        //resize array; this case is hard to imagine...
        char[] tempCh = currentEntity.ch;
        currentEntity.ch = new char[length+currentEntity.count-currentEntity.position+1];
        System.arraycopy(tempCh, 0, currentEntity.ch, 0, tempCh.length);
    }
    if(currentEntity.position < length) {
        // have to move sensitive stuff out of the way...
        System.arraycopy(currentEntity.ch, currentEntity.position, currentEntity.ch, length, currentEntity.count-currentEntity.position);
        currentEntity.count += length-currentEntity.position;
    } else {
        // have to reintroduce some whitespace so this parses:
        for(int i=length; i<currentEntity.position; i++)
            currentEntity.ch[i]=' ';
    }
    // prepend contents...
    System.arraycopy(scannedChars, 0, currentEntity.ch, 0, length);
    currentEntity.position = 0;
    currentEntity.baseCharOffset = 0;
    currentEntity.startPosition = 0;
    currentEntity.columnNumber = currentEntity.lineNumber = 1;
}
 
Example #18
Source File: XMLEntityScanner.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether the value of the specified Limit exceeds its limit
 *
 * @param limit The Limit to be checked
 * @param entity The current entity
 * @param offset The index of the first byte
 * @param length The length of the entity scanned
 */
protected void checkLimit(Limit limit, ScannedEntity entity, int offset, int length) {
    fLimitAnalyzer.addValue(limit, entity.name, length);
    if (fSecurityManager.isOverLimit(limit, fLimitAnalyzer)) {
        fSecurityManager.debugPrint(fLimitAnalyzer);
        Object[] e = (limit == Limit.ENTITY_REPLACEMENT_LIMIT) ?
                new Object[]{fLimitAnalyzer.getValue(limit),
                    fSecurityManager.getLimit(limit), fSecurityManager.getStateLiteral(limit)} :
                new Object[]{entity.name, fLimitAnalyzer.getValue(limit),
                    fSecurityManager.getLimit(limit), fSecurityManager.getStateLiteral(limit)};
        fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, limit.key(),
                e, XMLErrorReporter.SEVERITY_FATAL_ERROR);
    }
    if (fSecurityManager.isOverLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT, fLimitAnalyzer)) {
        fSecurityManager.debugPrint(fLimitAnalyzer);
        fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "TotalEntitySizeLimit",
                new Object[]{fLimitAnalyzer.getTotalValue(Limit.TOTAL_ENTITY_SIZE_LIMIT),
            fSecurityManager.getLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT),
            fSecurityManager.getStateLiteral(Limit.TOTAL_ENTITY_SIZE_LIMIT)},
                XMLErrorReporter.SEVERITY_FATAL_ERROR);
    }
}
 
Example #19
Source File: XMLEntityScanner.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks whether the end of the entity buffer has been reached. If yes,
 * checks against the limit and buffer size before loading more characters.
 *
 * @param entity the current entity
 * @param offset the offset from which the current read was started
 * @param nameOffset the offset from which the current name starts
 * @return the length of characters scanned before the end of the buffer,
 * zero if there is more to be read in the buffer
 */
protected int checkBeforeLoad(Entity.ScannedEntity entity, int offset,
        int nameOffset) throws IOException {
    int length = 0;
    if (++entity.position == entity.count) {
        length = entity.position - offset;
        int nameLength = length;
        if (nameOffset != -1) {
            nameOffset = nameOffset - offset;
            nameLength = length - nameOffset;
        } else {
            nameOffset = offset;
        }
        //check limit before loading more data
        checkLimit(Limit.MAX_NAME_LIMIT, entity, nameOffset, nameLength);
        invokeListeners(length);
        if (length == entity.ch.length) {
            // bad luck we have to resize our buffer
            char[] tmp = new char[entity.fBufferSize * 2];
            System.arraycopy(entity.ch, offset, tmp, 0, length);
            entity.ch = tmp;
            entity.fBufferSize *= 2;
        }
        else {
            System.arraycopy(entity.ch, offset, entity.ch, 0, length);
        }
    }
    return length;
}
 
Example #20
Source File: XMLEntityScanner.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/** set the instance of current scanned entity.
 *   @param ScannedEntity
 */

public final void setCurrentEntity(Entity.ScannedEntity scannedEntity){
    fCurrentEntity = scannedEntity ;
    if(fCurrentEntity != null){
        isExternal = fCurrentEntity.isExternal();
        if(DEBUG_BUFFER)
            System.out.println("Current Entity is "+scannedEntity.name);
    }
}
 
Example #21
Source File: XMLEntityScanner.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * If the current entity is an Entity reference, check the accumulated size
 * against the limit.
 *
 * @param nt type of name (element, attribute or entity)
 * @param entity The current entity
 * @param offset The index of the first byte
 * @param length The length of the entity scanned
 */
protected void checkEntityLimit(NameType nt, ScannedEntity entity, int offset, int length) {
    if (entity == null || !entity.isGE) {
        return;
    }

    if (nt != NameType.REFERENCE) {
        checkLimit(Limit.GENERAL_ENTITY_SIZE_LIMIT, entity, offset, length);
    }
    if (nt == NameType.ELEMENTSTART || nt == NameType.ATTRIBUTENAME) {
        checkNodeCount(entity);
    }
}
 
Example #22
Source File: XMLEntityScanner.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/** set the instance of current scanned entity.
 *   @param ScannedEntity
 */

public final void setCurrentEntity(Entity.ScannedEntity scannedEntity){
    fCurrentEntity = scannedEntity ;
    if(fCurrentEntity != null){
        isExternal = fCurrentEntity.isExternal();
        if(DEBUG_BUFFER)
            System.out.println("Current Entity is "+scannedEntity.name);
    }
}
 
Example #23
Source File: XMLEntityScanner.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/** set the instance of current scanned entity.
 *   @param ScannedEntity
 */

public final void setCurrentEntity(Entity.ScannedEntity scannedEntity){
    fCurrentEntity = scannedEntity ;
    if(fCurrentEntity != null){
        isExternal = fCurrentEntity.isExternal();
        if(DEBUG_BUFFER)
            System.out.println("Current Entity is "+scannedEntity.name);
    }
}
 
Example #24
Source File: XMLEntityScanner.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether the end of the entity buffer has been reached. If yes,
 * checks against the limit and buffer size before loading more characters.
 *
 * @param entity the current entity
 * @param offset the offset from which the current read was started
 * @param nameOffset the offset from which the current name starts
 * @return the length of characters scanned before the end of the buffer,
 * zero if there is more to be read in the buffer
 */
protected int checkBeforeLoad(Entity.ScannedEntity entity, int offset,
        int nameOffset) throws IOException {
    int length = 0;
    if (++entity.position == entity.count) {
        length = entity.position - offset;
        int nameLength = length;
        if (nameOffset != -1) {
            nameOffset = nameOffset - offset;
            nameLength = length - nameOffset;
        } else {
            nameOffset = offset;
        }
        //check limit before loading more data
        checkLimit(Limit.MAX_NAME_LIMIT, entity, nameOffset, nameLength);
        invokeListeners(length);
        if (length == entity.ch.length) {
            // bad luck we have to resize our buffer
            char[] tmp = new char[entity.fBufferSize * 2];
            System.arraycopy(entity.ch, offset, tmp, 0, length);
            entity.ch = tmp;
            entity.fBufferSize *= 2;
        }
        else {
            System.arraycopy(entity.ch, offset, entity.ch, 0, length);
        }
    }
    return length;
}
 
Example #25
Source File: XMLEntityScanner.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * If the current entity is an Entity reference, check the accumulated size
 * against the limit.
 *
 * @param nt type of name (element, attribute or entity)
 * @param entity The current entity
 * @param offset The index of the first byte
 * @param length The length of the entity scanned
 */
protected void checkEntityLimit(NameType nt, ScannedEntity entity, int offset, int length) {
    if (entity == null || !entity.isGE) {
        return;
    }

    if (nt != NameType.REFERENCE) {
        checkLimit(Limit.GENERAL_ENTITY_SIZE_LIMIT, entity, offset, length);
    }
    if (nt == NameType.ELEMENTSTART || nt == NameType.ATTRIBUTENAME) {
        checkNodeCount(entity);
    }
}
 
Example #26
Source File: XMLEntityScanner.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/** set the instance of current scanned entity.
 *   @param ScannedEntity
 */

public final void setCurrentEntity(Entity.ScannedEntity scannedEntity){
    fCurrentEntity = scannedEntity ;
    if(fCurrentEntity != null){
        isExternal = fCurrentEntity.isExternal();
        if(DEBUG_BUFFER)
            System.out.println("Current Entity is "+scannedEntity.name);
    }
}
 
Example #27
Source File: XMLEntityScanner.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks whether the end of the entity buffer has been reached. If yes,
 * checks against the limit and buffer size before loading more characters.
 *
 * @param entity the current entity
 * @param offset the offset from which the current read was started
 * @param nameOffset the offset from which the current name starts
 * @return the length of characters scanned before the end of the buffer,
 * zero if there is more to be read in the buffer
 */
protected int checkBeforeLoad(Entity.ScannedEntity entity, int offset,
        int nameOffset) throws IOException {
    int length = 0;
    if (++entity.position == entity.count) {
        length = entity.position - offset;
        int nameLength = length;
        if (nameOffset != -1) {
            nameOffset = nameOffset - offset;
            nameLength = length - nameOffset;
        } else {
            nameOffset = offset;
        }
        //check limit before loading more data
        checkLimit(Limit.MAX_NAME_LIMIT, entity, nameOffset, nameLength);
        invokeListeners(length);
        if (length == entity.ch.length) {
            // bad luck we have to resize our buffer
            char[] tmp = new char[entity.fBufferSize * 2];
            System.arraycopy(entity.ch, offset, tmp, 0, length);
            entity.ch = tmp;
            entity.fBufferSize *= 2;
        }
        else {
            System.arraycopy(entity.ch, offset, entity.ch, 0, length);
        }
    }
    return length;
}
 
Example #28
Source File: XMLEntityScanner.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * If the current entity is an Entity reference, check the accumulated size
 * against the limit.
 *
 * @param nt type of name (element, attribute or entity)
 * @param entity The current entity
 * @param offset The index of the first byte
 * @param length The length of the entity scanned
 */
protected void checkEntityLimit(NameType nt, ScannedEntity entity, int offset, int length) {
    if (entity == null || !entity.isGE) {
        return;
    }

    if (nt != NameType.REFERENCE) {
        checkLimit(Limit.GENERAL_ENTITY_SIZE_LIMIT, entity, offset, length);
    }
    if (nt == NameType.ELEMENTSTART || nt == NameType.ATTRIBUTENAME) {
        checkNodeCount(entity);
    }
}
 
Example #29
Source File: XMLEntityScanner.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * If the current entity is an Entity reference, check the accumulated size
 * against the limit.
 *
 * @param nt type of name (element, attribute or entity)
 * @param entity The current entity
 * @param offset The index of the first byte
 * @param length The length of the entity scanned
 */
protected void checkEntityLimit(NameType nt, ScannedEntity entity, int offset, int length) {
    if (entity == null || !entity.isGE) {
        return;
    }

    if (nt != NameType.REFERENCE) {
        checkLimit(Limit.GENERAL_ENTITY_SIZE_LIMIT, entity, offset, length);
    }
    if (nt == NameType.ELEMENTSTART || nt == NameType.ATTRIBUTENAME) {
        checkNodeCount(entity);
    }
}
 
Example #30
Source File: XMLEntityScanner.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether the end of the entity buffer has been reached. If yes,
 * checks against the limit and buffer size before loading more characters.
 *
 * @param entity the current entity
 * @param offset the offset from which the current read was started
 * @param nameOffset the offset from which the current name starts
 * @return the length of characters scanned before the end of the buffer,
 * zero if there is more to be read in the buffer
 */
protected int checkBeforeLoad(Entity.ScannedEntity entity, int offset,
        int nameOffset) throws IOException {
    int length = 0;
    if (++entity.position == entity.count) {
        length = entity.position - offset;
        int nameLength = length;
        if (nameOffset != -1) {
            nameOffset = nameOffset - offset;
            nameLength = length - nameOffset;
        } else {
            nameOffset = offset;
        }
        //check limit before loading more data
        checkLimit(Limit.MAX_NAME_LIMIT, entity, nameOffset, nameLength);
        invokeListeners(length);
        if (length == entity.ch.length) {
            // bad luck we have to resize our buffer
            char[] tmp = new char[entity.fBufferSize * 2];
            System.arraycopy(entity.ch, offset, tmp, 0, length);
            entity.ch = tmp;
            entity.fBufferSize *= 2;
        }
        else {
            System.arraycopy(entity.ch, offset, entity.ch, 0, length);
        }
    }
    return length;
}