You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2019/11/13 23:46:09 UTC

[couchdb] branch master updated: Send only as many bytes as requested by Range hdr (#2310)

This is an automated email from the ASF dual-hosted git repository.

kocolosk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/master by this push:
     new bd1e8a6  Send only as many bytes as requested by Range hdr (#2310)
bd1e8a6 is described below

commit bd1e8a6fcb414368ebf675ad24bc65eacadbb2d6
Author: Adam Kocoloski <ko...@apache.org>
AuthorDate: Wed Nov 13 18:45:57 2019 -0500

    Send only as many bytes as requested by Range hdr (#2310)
    
    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
---
 src/couch/src/couch_stream.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/couch/src/couch_stream.erl b/src/couch/src/couch_stream.erl
index 0335629..2ab46d7 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.