Skip to content

Commit

Permalink
Fix bug in SanitizingXmlFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaiter committed May 10, 2024
1 parent cbdfb79 commit 527f91d
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public int read(char[] cbuf, int off, int len) throws IOException {
while (idx < (off + numRead)) {
// Check for invalid entities and try to fix them
while (advancedFixing && idx < (off + numRead)) {
int match = multiIndexOf(cbuf, idx, '<', '&');
int match = multiIndexOf(cbuf, idx, (off + numRead), '<', '&');
if (match < 0 || match > (off + numRead)) {
// Nothing to do in this buffer
break outer;
Expand All @@ -99,7 +99,7 @@ public int read(char[] cbuf, int off, int len) throws IOException {
// Start of element, no more entities to check
break;
}
int entityEnd = multiIndexOf(cbuf, match + 1, '<', ';');
int entityEnd = multiIndexOf(cbuf, match + 1, (off + numRead), '<', ';');

if (entityEnd < match + 1) {
// Not enough data to determine entity end, we may have to carry over
Expand Down Expand Up @@ -205,7 +205,7 @@ public int read(char[] cbuf, int off, int len) throws IOException {
(cbuf[startElem + 1] == '/' || cbuf[startElem + 1] == '?')
? startElem + 2
: startElem + 1;
int endTag = multiIndexOf(cbuf, startTag, ' ', '\n', '\t');
int endTag = multiIndexOf(cbuf, startTag, (off + numRead), ' ', '\n', '\t');
if (endTag > endElem || endTag < 0) {
endTag = cbuf[endElem - 1] == '/' ? endElem - 1 : endElem;
}
Expand Down Expand Up @@ -290,14 +290,14 @@ public int read(char[] cbuf, int off, int len) throws IOException {
* Variant of {@link org.apache.commons.lang3.ArrayUtils#indexOf(char[], char)} that supports
* looking for multiple values.
*/
private static int multiIndexOf(final char[] array, int startIndex, final char... valuesToFind) {
private static int multiIndexOf(final char[] array, int startIndex, int limit, final char... valuesToFind) {
if (array == null) {
return -1;
}
if (startIndex < 0) {
startIndex = 0;
}
for (int i = startIndex; i < array.length; i++) {
for (int i = startIndex; i < limit; i++) {
for (char value : valuesToFind) {
if (value == array[i]) {
return i;
Expand Down

0 comments on commit 527f91d

Please sign in to comment.