fix(serialize-xml): prevent buffer underrun in XML reader
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
7b45a30fb7
commit
6ce27585f8
@ -618,7 +618,7 @@ public class NativeXmlReader implements Closeable {
|
||||
|
||||
pos = p;
|
||||
if (c == '<') {
|
||||
if (p == l) {
|
||||
if (p + 2 >= l) {
|
||||
pos--; // push back '/' so it's still in the buffer when this method returns
|
||||
boolean charsLoaded = fillBuffer(4);
|
||||
pos++; // consume the '/' again
|
||||
@ -837,7 +837,7 @@ public class NativeXmlReader implements Closeable {
|
||||
switch (peek()) {
|
||||
case BEGIN_TAG -> {
|
||||
beginTag();
|
||||
writer.beginTag(pathNames[stackSize - 1]);
|
||||
writer.beginTag(pathNames[stackSize - 2]);
|
||||
while (hasNext()) {
|
||||
copyTo(writer);
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ public class NativeXmlWriter implements Closeable, Flushable {
|
||||
private boolean wasText = false;
|
||||
|
||||
private boolean lenient = false;
|
||||
private boolean conciseTags = true;
|
||||
private boolean escapeNonAscii = true;
|
||||
public NativeXmlWriter(Writer out) {
|
||||
this.out = Objects.requireNonNull(out, "out == null");
|
||||
@ -72,6 +73,15 @@ public class NativeXmlWriter implements Closeable, Flushable {
|
||||
return indent;
|
||||
}
|
||||
|
||||
public NativeXmlWriter setConciseTags(boolean conciseTags) {
|
||||
this.conciseTags = conciseTags;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isConciseTags() {
|
||||
return conciseTags;
|
||||
}
|
||||
|
||||
public NativeXmlWriter setNewline(String newline) {
|
||||
if (newline == null || newline.isEmpty()) {
|
||||
this.newline = "";
|
||||
@ -133,6 +143,12 @@ public class NativeXmlWriter implements Closeable, Flushable {
|
||||
deferredText = null;
|
||||
}
|
||||
|
||||
if (context == TAG_HEAD && !conciseTags) {
|
||||
out.write('>');
|
||||
context = TAG_BODY;
|
||||
simple = true;
|
||||
}
|
||||
|
||||
stackSize--;
|
||||
if (context == TAG_BODY) {
|
||||
if (!simple) newline();
|
||||
|
Loading…
Reference in New Issue
Block a user