Skip to content

Commit

Permalink
Stream might not have reached the end even if it doesn't return reque…
Browse files Browse the repository at this point in the history
…sted amount of bytes
  • Loading branch information
tonihele committed Nov 4, 2023
1 parent 3c4af6f commit 28c2421
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,18 +428,22 @@ private static void populateByteArray(byte[] array, LittleEndien stream, int cou

if (dataLength == stride) {
int length = end - index;
int read = stream.read(array, 0, length);
assertReadLength(read, length);
int n = 0;
while (n < length) {
int cnt = stream.read(array, n, length - n);
if (cnt < 0) {
throw new AssetLoadException("Data ended prematurely");
}
n += cnt;
}

return;
}

int arrayIndex = 0;
byte[] buffer = new byte[numComponents];
while (index < end) {
int read = stream.read(buffer, 0, numComponents);
assertReadLength(read, numComponents);

stream.read(buffer, 0, numComponents);
System.arraycopy(buffer, 0, array, arrayIndex, numComponents);
arrayIndex += numComponents;
if (dataLength < stride) {
Expand All @@ -449,12 +453,6 @@ private static void populateByteArray(byte[] array, LittleEndien stream, int cou
}
}

private static void assertReadLength(int read, int length) {
if (read < length) {
throw new AssetLoadException("Data ended prematurely");
}
}

private static void populateShortArray(short[] array, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException {
int componentSize = format.getComponentSize();
int index = byteOffset;
Expand Down

0 comments on commit 28c2421

Please sign in to comment.