Skip to content

Commit

Permalink
Add separate docs tarball limits
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmach committed Feb 29, 2024
1 parent 8ba1693 commit fae27c4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/hex_core.erl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@
repo_verify => boolean(),
repo_verify_origin => boolean(),
tarball_max_size => pos_integer(),
tarball_max_uncompressed_size => pos_integer()
tarball_max_uncompressed_size => pos_integer(),
docs_tarball_max_size => pos_integer(),
docs_tarball_max_uncompressed_size => pos_integer()
}.

-spec default_config() -> config().
Expand All @@ -104,5 +106,7 @@ default_config() ->
repo_verify => true,
repo_verify_origin => true,
tarball_max_size => 8 * 1024 * 1024,
tarball_max_uncompressed_size => 64 * 1024 * 1024
tarball_max_uncompressed_size => 64 * 1024 * 1024,
docs_tarball_max_size => 16 * 1024 * 1024,
docs_tarball_max_uncompressed_size => 128 * 1024 * 1024
}.
5 changes: 3 additions & 2 deletions src/hex_tarball.erl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ create(Metadata, Files) ->
%% @end
-spec create_docs(files(), hex_core:config()) -> {ok, tarball()} | {error, term()}.
create_docs(Files, #{
tarball_max_size := TarballMaxSize, tarball_max_uncompressed_size := TarballMaxUncompressedSize
docs_tarball_max_size := TarballMaxSize,
docs_tarball_max_uncompressed_size := TarballMaxUncompressedSize
}) ->
UncompressedTarball = create_memory_tarball(Files),
UncompressedSize = byte_size(UncompressedTarball),
Expand Down Expand Up @@ -219,7 +220,7 @@ unpack(Tarball, Output) ->
-spec unpack_docs
(tarball(), memory, hex_core:config()) -> {ok, contents()} | {error, term()};
(tarball(), filename(), hex_core:config()) -> ok | {error, term()}.
unpack_docs(Tarball, _, #{tarball_max_size := TarballMaxSize}) when
unpack_docs(Tarball, _, #{docs_tarball_max_size := TarballMaxSize}) when
byte_size(Tarball) > TarballMaxSize
->
{error, {tarball, too_big}};
Expand Down
6 changes: 3 additions & 3 deletions test/hex_tarball_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,17 @@ unpack_error_handling_test(_Config) ->

docs_too_big_to_create_test(_Config) ->
Files = [{"index.html", <<"Docs">>}],
Config = maps:put(tarball_max_size, 100, hex_core:default_config()),
Config = maps:put(docs_tarball_max_size, 100, hex_core:default_config()),
{error, {tarball, {too_big_compressed, 100}}} = hex_tarball:create_docs(Files, Config),
Config1 = maps:put(tarball_max_uncompressed_size, 100, hex_core:default_config()),
Config1 = maps:put(docs_tarball_max_uncompressed_size, 100, hex_core:default_config()),
{error, {tarball, {too_big_uncompressed, 100}}} = hex_tarball:create_docs(Files, Config1),

ok.

docs_too_big_to_unpack_test(_Config) ->
Files = [{"index.html", <<"Docs">>}],
{ok, Tarball} = hex_tarball:create_docs(Files),
Config = maps:put(tarball_max_size, 100, hex_core:default_config()),
Config = maps:put(docs_tarball_max_size, 100, hex_core:default_config()),
{error, {tarball, too_big}} = hex_tarball:unpack_docs(Tarball, memory, Config),

ok.
Expand Down

0 comments on commit fae27c4

Please sign in to comment.