From commits-return-6460-apmail-couchdb-commits-archive=couchdb.apache.org@couchdb.apache.org Thu May 26 22:28:26 2011 Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2315C6815 for ; Thu, 26 May 2011 22:28:26 +0000 (UTC) Received: (qmail 97067 invoked by uid 500); 26 May 2011 22:28:26 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 97025 invoked by uid 500); 26 May 2011 22:28:26 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 97016 invoked by uid 99); 26 May 2011 22:28:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 May 2011 22:28:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 May 2011 22:28:23 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C0DE22388A93; Thu, 26 May 2011 22:28:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1128113 - in /couchdb/branches/1.0.x/src/couchdb: couch_db.erl couch_httpd_db.erl Date: Thu, 26 May 2011 22:28:02 -0000 To: commits@couchdb.apache.org From: rnewson@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110526222802.C0DE22388A93@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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,