Skip to content

Commit

Permalink
fix: end parsing if EOF is hit (#3223)
Browse files Browse the repository at this point in the history
  • Loading branch information
iBotPeaches committed Jul 26, 2023
1 parent ab79984 commit 772646f
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import brut.androlib.res.data.axml.NamespaceStack;
import brut.androlib.res.xml.ResXmlEncoders;
import brut.util.ExtDataInput;
import org.apache.commons.io.input.CountingInputStream;
import com.google.common.io.LittleEndianDataInputStream;
import org.xmlpull.v1.XmlPullParserException;
import java.io.DataInput;
Expand Down Expand Up @@ -65,6 +66,7 @@ public void setAttrDecoder(ResAttrDecoder attrDecoder) {
public void open(InputStream stream) {
close();
if (stream != null) {
stream = mCountIn = new CountingInputStream(stream);
// We need to explicitly cast to DataInput as otherwise the constructor is ambiguous.
// We choose DataInput instead of InputStream as ExtDataInput wraps an InputStream in
// a DataInputStream which is big-endian and ignores the little-endian behavior.
Expand All @@ -79,6 +81,7 @@ public void close() {
}
isOperational = false;
mIn = null;
mCountIn = null;
mStringBlock = null;
mResourceIds = null;
mNamespaces.reset();
Expand Down Expand Up @@ -677,6 +680,13 @@ private void doNext() throws IOException {
break;
}

// #2070 - Some applications have 2 start namespaces, but only 1 end namespace.
if (mCountIn.available() == 0) {
LOGGER.warning(String.format("AXML hit unexpected end of file at byte: 0x%X", mCountIn.getCount()));
mEvent = END_DOCUMENT;
break;
}

int chunkType;
int headerSize = 0;
if (event == START_DOCUMENT) {
Expand Down Expand Up @@ -788,6 +798,7 @@ private void setFirstError(AndrolibException error) {
}

private ExtDataInput mIn;
private CountingInputStream mCountIn;
private ResAttrDecoder mAttrDecoder;
private AndrolibException mFirstError;

Expand Down

0 comments on commit 772646f

Please sign in to comment.