emscripten-core / emscripten-core/emscripten

FetchFS: `getFileRange` issues out-of-bounds chunk requests

Open
#24,438 5 comments 0 reactions 0 assignees View on GitHub
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 allows requests for chunks outside the file boundaries. The server will then respond with `416 Range Not Satisfiable`, which is properly handled in the code but I think we should save ourselves the request in the first place.

I've applied the attached patch to resolve this problem. I'd submit a pull request but I don't have the time right now to set up a local test environment.

CC @JoeOsborn

[bounds.patch](https://github.com/user-attachments/files/20512114/bounds.patch)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.