Author: rnewson Date: Thu May 26 22:28:02 2011 New Revision: 1128113 URL: http://svn.apache.org/viewvc?rev=1128113&view=rev Log: COUCHDB-1177 - don't read more of an attachment than Content-Length states. (original patch by Paul Davis, awesomeness enhanced by Robert Newson). Conflicts: src/couchdb/couch_httpd_db.erl Modified: couchdb/branches/1.0.x/src/couchdb/couch_db.erl couchdb/branches/1.0.x/src/couchdb/couch_httpd_db.erl Modified: couchdb/branches/1.0.x/src/couchdb/couch_db.erl URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/src/couchdb/couch_db.erl?rev=1128113&r1=1128112&r2=1128113&view=diff ============================================================================== --- couchdb/branches/1.0.x/src/couchdb/couch_db.erl (original) +++ couchdb/branches/1.0.x/src/couchdb/couch_db.erl Thu May 26 22:28:02 2011 @@ -923,10 +923,15 @@ with_stream(Fd, #att{md5=InMd5,type=Type write_streamed_attachment(_Stream, _F, 0) -> ok; write_streamed_attachment(Stream, F, LenLeft) when LenLeft > 0 -> - Bin = F(), + Bin = read_next_chunk(F, LenLeft), ok = couch_stream:write(Stream, Bin), write_streamed_attachment(Stream, F, LenLeft - size(Bin)). +read_next_chunk(F, _) when is_function(F, 0) -> + F(); +read_next_chunk(F, LenLeft) when is_function(F, 1) -> + F(lists:min([LenLeft, 16#2000])). + enum_docs_since_reduce_to_count(Reds) -> couch_btree:final_reduce( fun couch_db_updater:btree_by_seq_reduce/2, Reds). Modified: couchdb/branches/1.0.x/src/couchdb/couch_httpd_db.erl URL: http://svn.apache.org/viewvc/couchdb/branches/1.0.x/src/couchdb/couch_httpd_db.erl?rev=1128113&r1=1128112&r2=1128113&view=diff ============================================================================== --- couchdb/branches/1.0.x/src/couchdb/couch_httpd_db.erl (original) +++ couchdb/branches/1.0.x/src/couchdb/couch_httpd_db.erl Thu May 26 22:28:02 2011 @@ -1025,7 +1025,7 @@ db_attachment_req(#httpd{method=Method,m end, - fun() -> couch_httpd:recv(Req, 0) end; + fun(Size) -> couch_httpd:recv(Req, Size) end; Length -> exit({length_not_integer, Length}) end,