-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
The method contract of InputStream.skipBytes() is:
Makes an attempt to skip over n bytes of data from the input stream, discarding the skipped bytes. However, it may skip over some smaller number of bytes, possibly zero. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. This method never throws an EOFException. The actual number of bytes skipped is returned.
This is nearly always not what you want and is a bountiful source of bugs. At a glance these locations in the code all use this method:
in.skipBytes(remainingChunkBytes); |
jmonkeyengine/jme3-core/src/plugins/java/com/jme3/texture/plugins/ktx/KTXLoader.java
Line 196 in 8cc3086
in.skipBytes(3 - ((nbPixelRead + 3) % 4)); |
jmonkeyengine/jme3-core/src/plugins/java/com/jme3/texture/plugins/DDSLoader.java
Line 163 in 8cc3086
in.skipBytes(4); // skip reserved value |
jmonkeyengine/jme3-desktop/src/main/java/com/jme3/cursors/plugins/CursorLoader.java
Line 131 in 8cc3086
leIn.skipBytes(8); // internal struct length (always 36) |
The one that impacted me was the GLTF loader, causing it to break on some asset imports.
I think this would be fixed for the GLTF loader with:
l/2553
All other places should probably use a helper utility that will skip exactly as many bytes as requested.