Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,21 @@ private static void populateByteArray(byte[] array, LittleEndien stream, int cou
int stride = Math.max(dataLength, byteStride);
int end = count * stride + byteOffset;
stream.skipBytes(byteOffset);

if (dataLength == stride) {
byte[] buffer = new byte[end - index];
stream.read(buffer, 0, buffer.length);
Copy link
Contributor

@pspeed42 pspeed42 Oct 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: read() may read fewer bytes than buffer.length and it's bad practice to ignore its return value. I'd suggest using readFully() instead but JME's LittleEndien.readFully() is broken in a similar way. This is a really dangerous way to read because failures will look really strange and not necessarily point to this read() code.

System.arraycopy(buffer, 0, array, 0, buffer.length);

return;
}

int arrayIndex = 0;
byte[] buffer = new byte[numComponents];
while (index < end) {
for (int i = 0; i < numComponents; i++) {
array[arrayIndex] = stream.readByte();
arrayIndex++;
}
stream.read(buffer, 0, numComponents);
System.arraycopy(buffer, 0, array, arrayIndex, numComponents);
arrayIndex += numComponents;
if (dataLength < stride) {
stream.skipBytes(stride - dataLength);
}
Expand Down