GLTF: Incorrect useage of InputStream.skipBytes()
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:
https://github.com/jMonkeyEngine/jmonkeyengine/blob/8cc308616271604f13f9311207cc1e5ebd7a8169/jme3-core/src/plugins/java/com/jme3/audio/plugins/WAVLoader.java#L175 https://github.com/jMonkeyEngine/jmonkeyengine/blob/8cc308616271604f13f9311207cc1e5ebd7a8169/jme3-core/src/plugins/java/com/jme3/texture/plugins/ktx/KTXLoader.java#L196 https://github.com/jMonkeyEngine/jmonkeyengine/blob/8cc308616271604f13f9311207cc1e5ebd7a8169/jme3-core/src/plugins/java/com/jme3/texture/plugins/DDSLoader.java#L163 https://github.com/jMonkeyEngine/jmonkeyengine/blob/8cc308616271604f13f9311207cc1e5ebd7a8169/jme3-desktop/src/main/java/com/jme3/cursors/plugins/CursorLoader.java#L131
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.
Thanks for reporting the issue.
Some of the stream types do enforce skips, like FileInputStream. Streams that read on these streams will inherit this enforcement. So, in common use cases, this is affecting only a very small set of instances of skipBytes in the engine.
My impression from reading the affected code is that the developer assumed the LittleEndian stream would guarantee skips. Therefore, I think the best approach is to fix LittleEndian to provide that behavior.