diff options
author | Bessenyei Balázs Donát <bessbd@users.noreply.github.com> | 2021-02-01 20:09:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-01 20:09:39 +0100 |
commit | 0837b5162708d1c4482e404cc7488f70f2d1e301 (patch) | |
tree | 6a30bb8085a8de1d27af963b8268497e43becfbd | |
parent | 8a5323cc97ecb085cf2dcf340433180809ca6820 (diff) | |
download | couchdb-0837b5162708d1c4482e404cc7488f70f2d1e301.tar.gz |
Set a finite default for max_attachment_size (#3347)
The current default for max_attachment_size is infinity.
This commit changes that to 1 gibibyte.
-rw-r--r-- | rel/overlay/etc/default.ini | 2 | ||||
-rw-r--r-- | src/couch/src/couch_att.erl | 27 | ||||
-rw-r--r-- | src/couch/test/eunit/couch_doc_tests.erl | 1 |
3 files changed, 26 insertions, 4 deletions
diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini index 3abe7578d..2cacf7775 100644 --- a/rel/overlay/etc/default.ini +++ b/rel/overlay/etc/default.ini @@ -47,7 +47,7 @@ changes_doc_ids_optimization_threshold = 100 max_document_size = 8000000 ; bytes ; ; Maximum attachment size. -; max_attachment_size = infinity +; max_attachment_size = 1073741824 ; 1 gibibyte ; ; Do not update the least recently used DB cache on reads, only writes ;update_lru_on_read = false diff --git a/src/couch/src/couch_att.erl b/src/couch/src/couch_att.erl index 8a3d6b101..12ac4874c 100644 --- a/src/couch/src/couch_att.erl +++ b/src/couch/src/couch_att.erl @@ -178,6 +178,8 @@ -type att() :: #att{} | attachment() | disk_att(). +-define(GB, (1024*1024*1024)). + new() -> %% We construct a record by default for compatability. This will be %% upgraded on demand. A subtle effect this has on all attachments @@ -732,13 +734,25 @@ upgrade_encoding(true) -> gzip; upgrade_encoding(false) -> identity; upgrade_encoding(Encoding) -> Encoding. - max_attachment_size() -> - case config:get("couchdb", "max_attachment_size", "infinity") of + max_attachment_size(config:get("couchdb", "max_attachment_size", ?GB)). + +max_attachment_size(MaxAttSizeConfig) -> + case MaxAttSizeConfig of "infinity" -> infinity; + MaxAttSize when is_list(MaxAttSize) -> + try list_to_integer(MaxAttSize) of + Result -> Result + catch _:_ -> + couch_log:error("invalid config value for max attachment size: ~p ", [MaxAttSize]), + throw(internal_server_error) + end; + MaxAttSize when is_integer(MaxAttSize) -> + MaxAttSize; MaxAttSize -> - list_to_integer(MaxAttSize) + couch_log:error("invalid config value for max attachment size: ~p ", [MaxAttSize]), + throw(internal_server_error) end. @@ -949,4 +963,11 @@ test_transform() -> ?assertEqual(1, fetch(counter, Transformed)). +max_attachment_size_test_() -> + {"Max attachment size tests", [ + ?_assertEqual(infinity, max_attachment_size("infinity")), + ?_assertEqual(5, max_attachment_size(5)), + ?_assertEqual(5, max_attachment_size("5")) + ]}. + -endif. diff --git a/src/couch/test/eunit/couch_doc_tests.erl b/src/couch/test/eunit/couch_doc_tests.erl index cf41df61d..fc63d3f30 100644 --- a/src/couch/test/eunit/couch_doc_tests.erl +++ b/src/couch/test/eunit/couch_doc_tests.erl @@ -139,6 +139,7 @@ mock_config() -> meck:expect(config, get, fun("couchdb", "max_document_id_length", "infinity") -> "1024"; ("couchdb", "max_attachment_size", "infinity") -> "infinity"; + ("couchdb", "max_attachment_size", 1073741824) -> 1073741824; ("mem3", "shards_db", "_dbs") -> "_dbs"; (Key, Val, Default) -> meck:passthrough([Key, Val, Default]) end |