summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2015-11-17 13:33:00 +0100
committerLinus Nordberg <linus@nordu.net>2016-02-01 11:40:25 +0100
commit46b997342a7b6ee592357730f39dd9b3f2ca3ae4 (patch)
treed7182a6ecc16a92fee2b40d49df8ad0419b07678 /src
parente9c106358e87d37a3592a980fc000aa9caea5bf4 (diff)
Add config knob max_submit_size.
If a blob is larger than this, in octets, after Base64 decoding, the submission is rejected with 400.
Diffstat (limited to 'src')
-rw-r--r--src/v1.erl13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/v1.erl b/src/v1.erl
index a52171e..7b7f6bf 100644
--- a/src/v1.erl
+++ b/src/v1.erl
@@ -157,8 +157,19 @@ add_blob(Input) ->
{'EXIT', _} ->
err400("add-blob: invalid base64-encoded blob", Blob);
DecodedBlob ->
- success(catlfish:add_chain(DecodedBlob, [], normal))
+ add_blob_helper(DecodedBlob,
+ application:get_env(catlfish,
+ max_submit_size,
+ 0))
end;
_ ->
err400("add-blob: missing input: blob", Input)
end.
+
+add_blob_helper(Blob, MaxSize) when MaxSize == 0 ->
+ success(catlfish:add_chain(Blob, [], normal));
+add_blob_helper(Blob, MaxSize) when erlang:size(Blob) =< MaxSize ->
+ add_blob_helper(Blob, 0);
+add_blob_helper(Blob, MaxSize) ->
+ err400(io_lib:format("add-blob: blob too large (~p > ~p)",
+ [erlang:size(Blob), MaxSize]), Blob).