fix: Read TypeHeader with min size REAndroid/APKEditor#15

This commit is contained in:
REAndroid 2023-03-21 12:13:58 -04:00
parent fcee142be9
commit 3e87435a1d
4 changed files with 20 additions and 2 deletions

View File

@ -53,6 +53,9 @@ import java.util.List;
public HeaderBlock(ChunkType chunkType){ public HeaderBlock(ChunkType chunkType){
this(chunkType.ID); this(chunkType.ID);
} }
public int getMinimumSize(){
return countBytes();
}
public ByteArray getExtraBytes() { public ByteArray getExtraBytes() {
return extraBytes; return extraBytes;
} }

View File

@ -30,6 +30,12 @@
public InfoHeader() { public InfoHeader() {
this((short) 0); this((short) 0);
} }
@Override
public int getMinimumSize(){
return INFO_MIN_SIZE;
}
@Override @Override
void initExtraBytes(ByteArray extraBytes, int difference){ void initExtraBytes(ByteArray extraBytes, int difference){
} }
@ -55,4 +61,6 @@
infoHeader.readBytes(blockReader); infoHeader.readBytes(blockReader);
return infoHeader; return infoHeader;
} }
private static final int INFO_MIN_SIZE = 8;
} }

View File

@ -44,6 +44,10 @@ public class TypeHeader extends HeaderBlock{
addChild(config); addChild(config);
} }
@Override
public int getMinimumSize(){
return TYPE_MIN_SIZE;
}
public ByteItem getId() { public ByteItem getId() {
return id; return id;
} }
@ -72,4 +76,7 @@ public class TypeHeader extends HeaderBlock{
+", entriesStart=" + getEntriesStart() +", entriesStart=" + getEntriesStart()
+", config=" + getConfig() + '}'; +", config=" + getConfig() + '}';
} }
//typeHeader.countBytes() - getConfig().countBytes() + ResConfig.SIZE_16
private static final int TYPE_MIN_SIZE = 36;
} }

View File

@ -70,7 +70,7 @@ import java.io.*;
} }
public TypeHeader readTypeHeader() throws IOException{ public TypeHeader readTypeHeader() throws IOException{
TypeHeader typeHeader = new TypeHeader(); TypeHeader typeHeader = new TypeHeader();
if(available() < typeHeader.countBytes()){ if(available() < typeHeader.getMinimumSize()){
return null; return null;
} }
int pos = getPosition(); int pos = getPosition();
@ -80,7 +80,7 @@ import java.io.*;
} }
public InfoHeader readHeaderBlock() throws IOException { public InfoHeader readHeaderBlock() throws IOException {
InfoHeader infoHeader = new InfoHeader(); InfoHeader infoHeader = new InfoHeader();
if(available() < infoHeader.countBytes()){ if(available() < infoHeader.getMinimumSize()){
return null; return null;
} }
int pos = getPosition(); int pos = getPosition();