Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Add max_document_size checking for multipart PUT requests
Previously multipart/related PUT requests didn't check maximum request sizes.

This commit checks content-length and compares that with the maximum.

This means keeping the current "semantics" of max_document_size which actually
means "max request size". But this makes the check more efficient and can
be done earlier in request processing time.

Jira: COUCHDB-3174
  • Loading branch information
nickva committed Oct 4, 2016
1 parent f129308 commit 7dec013e8dc12db718ce124ad07f62b7cd3f7419
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
@@ -33,6 +33,8 @@
-export([http_1_0_keep_alive/2]).
-export([validate_host/1]).
-export([validate_bind_address/1]).
-export([check_max_request_length/1]).


-define(HANDLER_NAME_IN_MODULE_POS, 6).

@@ -446,6 +448,18 @@ validate_ctype(Req, Ctype) ->
end
end.


check_max_request_length(Req) ->
Len = list_to_integer(header_value(Req, "Content-Length", "0")),
MaxLen = config:get_integer("couchdb", "max_document_size", 4294967296),
case Len > MaxLen of
true ->
exit({body_too_large, Len});
false ->
ok
end.


% Utilities

partition(Path) ->
@@ -583,6 +583,7 @@ db_doc_req(#httpd{method='PUT'}=Req, Db, DocId) ->

case couch_util:to_list(couch_httpd:header_value(Req, "Content-Type")) of
("multipart/related;" ++ _) = ContentType ->
couch_chttpd:check_max_request_length(Req),
{ok, Doc0, WaitFun, Parser} = couch_doc:doc_from_multi_part_stream(
ContentType, fun() -> receive_request_data(Req) end),
Doc = couch_doc_from_req(Req, DocId, Doc0),

0 comments on commit 7dec013

Please sign in to comment.