Skip to content

Conversation

riccardobl
Copy link
Member

@riccardobl riccardobl commented Sep 17, 2025

Fixes #2555 across the entire engine.

This PR fixes the implementation of LittleEndien.readFully() and introduces two new utility methods in ByteUtils:

  • readFully
  • skipFully

Both ensure that the requested number of bytes are reliably read or skipped, even if the underlying stream does not return the full amount in a single call.

The changes are not yet fully tested, but they are part of the codebase I am actively working with. Additional testing and verification from others would be greatly appreciated.

@riccardobl riccardobl added bug Something that is supposed to work, but doesn't. More severe than a "defect". Contribution welcome labels Sep 17, 2025
@ScottPeterJohnson
Copy link

This patch may (still) actually cause an issue with GLTF loader. Essentially requiring the "full skip" and erroring on EOF can cause failure. From an asset I'm working with:

int end = count * stride + byteOffset; //1839200, when the actual byte array backing it is only 1839188 long
        stream.skipBytes(byteOffset);
        while (index < end) {
            //Index is 1839136, reads the last value
            for (int i = 0; i < numComponents; i++) {
                buffer.put(readAsFloat(stream, format));
            }
            if (dataLength < stride) {
                //Tries to skip 52 bytes; but 1839136+52=1839200 > 1839188
                stream.skipBytes(stride - dataLength);
                //Throws EOFException here
            }
            index += stride; //Would set index to 1839200 and skip loop
        }

(I'd add the asset as example since it messes up so much, but it's Unreal licensed.)

@yaRnMcDonuts yaRnMcDonuts added this to the v3.9.0 milestone Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is supposed to work, but doesn't. More severe than a "defect". Contribution welcome
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GLTF: Incorrect useage of InputStream.skipBytes()
4 participants