Bug 4766 - httpd fails to honor byte range requests if the range begins with 0
Summary: httpd fails to honor byte range requests if the range begins with 0
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Networking (show other bugs)
Version: 1.19.x
Hardware: All All
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-17 19:45 UTC by Rob Walker
Modified: 2012-02-19 16:20 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
change byte range test to use a separate boolean (2.14 KB, patch)
2012-02-17 19:47 UTC, Rob Walker
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rob Walker 2012-02-17 19:45:35 UTC
Httpd fails to honor byte range requests if the range begins with 0.

Whether to return a byte range is predicated on the value of range_start (treated as a boolean).  If range start is 0, httpd treats the request as if it were for the entire file.

Range: bytes=0-1 of a 100 byte file returns 100 bytes.
Comment 1 Rob Walker 2012-02-17 19:47:19 UTC
Created attachment 4046 [details]
change byte range test to use a separate boolean
Comment 2 Rob Walker 2012-02-18 05:51:59 UTC
I don't know how sensitive BusyBox is to a word vs. a byte vs. a bit for data.  Negative values of range_start could also be used as a positive boolean, instead of the smallint range_req I've proposed.

To summarize:
if a range is requested and the Range: header is reasonable, set range_start to requested value | ~MAX_INT (sets high bit)

range_start == 0 => no byte range requested or served
range_start != 0 => serve a byte range starting from (range_start ^ ~MAX_INT)

I don't know if BusyBox httpd has been tested or is expected to work with > 2GB files, though.
Comment 3 Bernhard Reutner-Fischer 2012-02-18 10:57:20 UTC
(In reply to comment #2)
> I don't know how sensitive BusyBox is to a word vs. a byte vs. a bit for data. 

You can check the size increase with
$ scripts/bloat-o-meter busybox_unstripped.unpatched busybox_unstripped
(cp busybox_unstripped busybox_unstripped.unpatched for a pristine build, then apply your patch and rebuild).

> Negative values of range_start could also be used as a positive boolean,
> instead of the smallint range_req I've proposed.
> 
> To summarize:
> if a range is requested and the Range: header is reasonable, set range_start to
> requested value | ~MAX_INT (sets high bit)
> 
> range_start == 0 => no byte range requested or served
> range_start != 0 => serve a byte range starting from (range_start ^ ~MAX_INT)
> 
> I don't know if BusyBox httpd has been tested or is expected to work with > 2GB
> files, though.

The httpd works fine with files > 2GB, yes.
Comment 4 Denys Vlasenko 2012-02-19 16:15:59 UTC
I propose to change "range_start != 0" condition for range_start >= 0 everywhere, and set range_start = -1 when range is off.