Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

End of file can be lost if the requested range exceeds the file length #7

Open
countingpine opened this issue Mar 16, 2023 · 0 comments

Comments

@countingpine
Copy link

countingpine commented Mar 16, 2023

I have found this problem in the wild on a 20i web host.

On the 20i CDN, it seems that for paths that end in "streamable" extensions (e.g. \.mp3$, \.wav$) which are handled by PHP (e.g. rewritten in .htaccess), HTTP requests will always be split up behind the scenes into ranges of whole megabyte-sized blocks (e.g. bytes=0-1048575, bytes=1048576-2097151).

The smartReadFile function uses these values as given for $begin and $end, and the Content-Length will be based on these.

But for the final block, if it's not a whole megabyte, then the fread loop will go past the end of the file, less data will be returned than expected from the Content-Length, and 20i will return nothing for this block.

The effective result is that the amount of data received will be rounded down to the nearest whole megabyte.

I think this can be fixed simply by ensuring the $end value is only updated if the new value is lower than the original ($size - 1).

I can submit a pull request for this if that would be helpful, but PHP is not my most fluent language.

countingpine added a commit to countingpine/smartReadFile that referenced this issue Mar 20, 2023
If the range end was too high, the function would try (and fail) to return the full range asked for.

Fixes Issue happyworm#7.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant