|
21 | 21 |
|
22 | 22 | import java.io.EOFException;
|
23 | 23 | import java.io.IOException;
|
| 24 | +import java.math.BigInteger; |
| 25 | +import java.util.logging.Logger; |
24 | 26 |
|
25 | 27 | public class ARSCHeader {
|
26 | 28 | public final short type;
|
@@ -48,6 +50,28 @@ public static ARSCHeader read(ExtDataInput in, CountingInputStream countIn) thro
|
48 | 50 | return new ARSCHeader(type, in.readShort(), in.readInt(), start);
|
49 | 51 | }
|
50 | 52 |
|
| 53 | + public void skipRemainingHeader(ExtDataInput in, CountingInputStream countIn) throws IOException { |
| 54 | + // Some applications lie about the reported size of their chunk header. Trusting the chunkSize is misleading |
| 55 | + // So compare to what we actually read in the header vs reported and skip the rest. |
| 56 | + int actualHeaderSize = countIn.getCount() - this.startPosition; |
| 57 | + int exceedingSize = this.headerSize - actualHeaderSize; |
| 58 | + if (exceedingSize > 0) { |
| 59 | + byte[] buf = new byte[exceedingSize]; |
| 60 | + in.readFully(buf); |
| 61 | + BigInteger exceedingBI = new BigInteger(1, buf); |
| 62 | + |
| 63 | + if (exceedingBI.equals(BigInteger.ZERO)) { |
| 64 | + LOGGER.fine(String.format("Chunk header size (%d), read (%d), but exceeding bytes are all zero.", |
| 65 | + this.headerSize, actualHeaderSize |
| 66 | + )); |
| 67 | + } else { |
| 68 | + LOGGER.warning(String.format("Chunk header size (%d), read (%d). Exceeding bytes: 0x%X.", |
| 69 | + this.headerSize, actualHeaderSize, exceedingBI |
| 70 | + )); |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + |
51 | 75 | public void skipChunk(ExtDataInput in) throws IOException {
|
52 | 76 | in.skipBytes(chunkSize - headerSize);
|
53 | 77 | }
|
@@ -76,4 +100,6 @@ public void skipChunk(ExtDataInput in) throws IOException {
|
76 | 100 | public final static short RES_XML_CDATA_TYPE = 0x0104;
|
77 | 101 | public final static short RES_XML_LAST_CHUNK_TYPE = 0x017f;
|
78 | 102 | public final static short RES_XML_RESOURCE_MAP_TYPE = 0x0180;
|
| 103 | + |
| 104 | + private static final Logger LOGGER = Logger.getLogger(ARSCHeader.class.getName()); |
79 | 105 | }
|
0 commit comments