summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Kocoloski <kocolosk@apache.org>2019-11-13 12:40:21 -0500
committerAdam Kocoloski <kocolosk@apache.org>2019-11-13 12:40:21 -0500
commit44c8702473358102d633d7813f07e4f8b61ead78 (patch)
tree22afef973590cb706c2080b86f8690c72b9ab0a7
parentec23c342b722db289c3dd54fc61221ae26dec7b5 (diff)
downloadcouchdb-fix/2244-range-request-too-much-data.tar.gz
Send only as many bytes as requested by Range hdrfix/2244-range-request-too-much-data
We have been failing to honor Range requests that specify an ending byte less than the final byte of an attachment. The code that was supposed to truncate the binary to the desired length was actually executing a noop statement that preserved the entire binary. Many HTTP clients will ignore the extra bytes on the wire and so this bug has gone undetected for a long time. Newer releases of libcurl that disable HTTP/0.9 support do detect it, and so we implicitly have a test for this in attachment_ranges.js, but ideally we'd have a more explicit one at some point in the future. Fixes #2244
-rw-r--r--src/couch/src/couch_stream.erl2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/couch/src/couch_stream.erl b/src/couch/src/couch_stream.erl
index 033562932..2ab46d7e7 100644
--- a/src/couch/src/couch_stream.erl
+++ b/src/couch/src/couch_stream.erl
@@ -145,7 +145,7 @@ foldl_length(Bin, {Length, UserFun, UserAcc}) ->
true ->
{Length - BinSize, UserFun, UserFun(Bin, UserAcc)};
false ->
- <<Trunc:BinSize/binary, _/binary>> = Bin,
+ <<Trunc:Length/binary, _/binary>> = Bin,
throw({finished, UserFun(Trunc, UserAcc)})
end.