emscripten-core / emscripten-core/emscripten
FetchFS: `getFileRange` doesn't respect response header `Content-Range` when requesting chunks
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
**Version of emscripten/emsdk:**
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.9 (bbf1caa6e24f64fca9eb6a13a9e02d3f42123e77)
clang version 21.0.0git (https:/github.com/llvm/llvm-project 2f05451198e2f222ec66cec4892ada0509519290)
Target: wasm32-unknown-emscripten
Thread model: posix
```
The [`getFileRange` function](https://github.com/emscripten-core/emscripten/blob/1d35dfbd0a48a48c203da01bb5c1f8ec3a6e2047/src/lib/libwasmfs_fetch.js#L23) in FetchFS currently doesn't respect the server's `Content-Range` response. It it legal for a server to respond with a range smaller than the one requested. Currently, there is an implicit assumption that the server fully serves the requested range and the chunks are filled with empty array in case data is missing. The function assumes the data has been fully received, even though it hasn't been.
Code in question: https://github.com/emscripten-core/emscripten/blob/1d35dfbd0a48a48c203da01bb5c1f8ec3a6e2047/src/lib/libwasmfs_fetch.js#L100
We should probably issue multiple requests until we have fully satisfied the requested range. It's also probably a good idea to refactor `getFileRange` (split into smaller functions) to accomodate for this extra logic, since it's already pretty complex as-is.
Contributor guide
Assessment
This issue has not been assessed yet.