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){
this(chunkType.ID);
}
public int getMinimumSize(){
return countBytes();
}
public ByteArray getExtraBytes() {
return extraBytes;
}

View File

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

View File

@ -44,6 +44,10 @@ public class TypeHeader extends HeaderBlock{
addChild(config);
}
@Override
public int getMinimumSize(){
return TYPE_MIN_SIZE;
}
public ByteItem getId() {
return id;
}
@ -72,4 +76,7 @@ public class TypeHeader extends HeaderBlock{
+", entriesStart=" + getEntriesStart()
+", 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{
TypeHeader typeHeader = new TypeHeader();
if(available() < typeHeader.countBytes()){
if(available() < typeHeader.getMinimumSize()){
return null;
}
int pos = getPosition();
@ -80,7 +80,7 @@ import java.io.*;
}
public InfoHeader readHeaderBlock() throws IOException {
InfoHeader infoHeader = new InfoHeader();
if(available() < infoHeader.countBytes()){
if(available() < infoHeader.getMinimumSize()){
return null;
}
int pos = getPosition();