BlockFileLoader: fix end-of-file handling issue

When reads return fewer bytes than requested, it's either an end-of-file
or an error. For now, we'll treat it as end-of-file.
This commit is contained in:
Sean Gilligan 2023-08-14 14:47:03 -07:00 committed by Andreas Schildbach
parent 2248513489
commit c5cbff1e47

View File

@ -165,10 +165,18 @@ public class BlockFileLoader implements Iterable<Block> {
break;
}
byte[] sizeBytes = new byte[4];
currentFileStream.read(sizeBytes, 0, 4);
int sizeBytesRead = currentFileStream.read(sizeBytes, 0, 4);
if (sizeBytesRead != 4) {
nextBlock = null;
return;
}
long size = ByteUtils.readUint32(sizeBytes, 0);
byte[] dataBytes = new byte[(int) size];
currentFileStream.read(dataBytes, 0, (int) size);
int dataBytesRead = currentFileStream.read(dataBytes, 0, (int) size);
if (dataBytesRead != size) {
nextBlock = null;
return;
}
try {
nextBlock = serializer.makeBlock(ByteBuffer.wrap(dataBytes));
} catch (ProtocolException e) {