Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DISCUSS] Validate new document writes against max_http_request_size #1253

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
hardcode mock uuid
  • Loading branch information
janl committed Jul 13, 2018
commit 616ec02aefbddff4bb37f87d2edf2539127c40f7
2 changes: 1 addition & 1 deletion src/couch/src/couch_doc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ from_json_obj_validate(EJson, DbName) ->
validate_total_document_size(#doc{id=DocId, body=Body, atts=Atts0}=Doc) ->
couch_log:debug("~nData: ~p~n", [Doc]),
MaxReqSize = config:get_integer("httpd", "max_http_request_size", 4294967296), % 4 GB
Boundary = couch_uuids:random(), % mock boundary, is only used for the length
Boundary = <<"d07e231b4fc27759fd822449377fcba7">>,
Atts = lists:map(fun couch_att:to_tuple/1, Atts0),
{_, DocSum} = couch_httpd_multipart:length_multipart_stream(Boundary,
?JSON_ENCODE(Body), Atts),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we re-encode, we use jiffy, but unless it is a request made by the replicator, the user probably didn't use erlang to encode the data, so we could get a different value. There is also some performance loss in say re-encoding larger document bodies back to json just to check their size.

There is no canonical json encoding and so no canonical encoded json size. Above we are calculating the encoded size using a conservative size estimate (giving the user a benefit of the doubt) and with better performance (https://github.com/nickva/couch_ebench). Maybe make a version of length calculation that takes sizes and then we'd pass the already computed couch_ejson_size:encoded_size(Doc#doc.body) and 32 for boundary size.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nickva, I’ll give this a ponder!

Expand Down