sokol_fetch seems to always fail with SFETCH_ERROR_UNEXPECTED_EOF on Windows

Created on 30 Mar 2020  路  5Comments  路  Source: floooh/sokol

Hi, thanks for the awesome libraries!

Recently I have been experimenting with using sokol_fetch for asset management, however I have run into a bit of trouble.

No matter what I do, I seem to get SFETCH_ERROR_UNEXPECTED_EOF when attempting to read files on Windows. A bit of debugging led me to this line (line 1649):

BOOL read_res = ReadFile(h, ptr, (DWORD)num_bytes, &bytes_read, NULL);

which returns 0, which leads to the SFETCH_ERROR_UNEXPECTED_EOF. Adding a bit of dumb Windows debugging code afterwards:

if (!read_res) {

    LPVOID lpMsgBuf;
    LPVOID lpDisplayBuf;
    DWORD dw = GetLastError();

    FormatMessage(
        FORMAT_MESSAGE_ALLOCATE_BUFFER |
        FORMAT_MESSAGE_FROM_SYSTEM |
        FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL,
        dw,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPTSTR)&lpMsgBuf,
        0, NULL);

    printf("Failed with error: %s", lpMsgBuf);
}

gives the message: Failed with error: Invalid access to memory location.

At first I thought (hoped) that this error was because we specify paths with native, absolute, windows paths (e.g. C:\Dev\something\etc\test.txt). However, changing to relative "unix" paths (e.g. something/etc/test.txt) did not help either.

Might also be worth mentioning that it seems to work fine when run on the web through emscripten.

Any ideas what might be the error? Hopefully it's just a user-error on our part :)

bug

Most helpful comment

Hmm that error message is associated with ERROR_NOACCESS, that gives me something to google for... it seems to be a buffer overflow of some sort, ReadFile() trying to read more bytes than fit into the provided buffer, which might either be a subtle bug in the code, or the provided buffer size is bigger than the actual buffer memory allocation.

I'll try to come up with a reproduction.

All 5 comments

Just wanted to give a quick update. We decided to not use sokol_fetch for our file management at this point (not only because of this, it turns out our needs are slightly different than what sokol_fetch is designed to provide).

As a result this issue is no longer particularly important to us, feel free to close it. But I guess it might be worthwhile to keep open if anyone else has this problem.

Oki doki, would still be good to know what caused the issue. It doesn't seem to be a general problem of the Windows code path, since the cgltf-sapp and loadpng-sapp samples are working for me on my Win10 machine... (I also don't remember problems with my emulators, which are loading game images).

Did you only test with text files? Maybe I overlooked something in CreateFileW() behaviour and Windows is modifying the line ends (e.g. CR to CRLF or similar).

I'll try to do some more experiments. Anyway, thanks for the bug report :)

Oh wait, I somehow skipped this:

Failed with error: Invalid access to memory location.

That's interesting indeed...

Hmm that error message is associated with ERROR_NOACCESS, that gives me something to google for... it seems to be a buffer overflow of some sort, ReadFile() trying to read more bytes than fit into the provided buffer, which might either be a subtle bug in the code, or the provided buffer size is bigger than the actual buffer memory allocation.

I'll try to come up with a reproduction.

We were mainly trying to load text files (more specifically .json files) in our initial tests, which caused these issues. Not sure if it matters, but we specified a significantly larger buffer than needed to write to up front in the sfetch_request_t.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amerkoleci picture amerkoleci  路  4Comments

septag picture septag  路  6Comments

serkonda7 picture serkonda7  路  4Comments

bqqbarbhg picture bqqbarbhg  路  3Comments

mhalber picture mhalber  路  5Comments