Clamp end of range request to be the length of the file

Fixes #3118.