rxi / sandbird

A tiny embeddable HTTP server written in C89
MIT License
174 stars 27 forks source link

Fixed 2 GB file size limit in sb_send_file() #3

Open toaarnio opened 5 years ago

toaarnio commented 5 years ago

First of all, thanks for making Sandbird available, it's the smallest and easiest to use embeddable web server that I've found. I realize there's not been much activity here in the past three years, but I hope there's someone still around to review this pull request...

So there was a problem trying to send files bigger than 2 GB. The sb_send_file() implementation was using size_t which is 32-bit, and that was causing the "Content-Length" value in the HTTP response to be truncated to 2^31. Using off_t instead of size_t fixes the issue because it's guaranteed to be 64-bit when compiled with -D _FILE_OFFSET_BITS=64.