Skip to content

Commit f996de4

Browse files
authored
Validate package files in mix hex.build (#1153)
* Validate package files in mix hex.build * Temporarily vendor tarball create validation * Delegate package file validation to hex_core * Sync root-relative tarball source validation * Vendor updated hex_core tarball files
1 parent f7417ef commit f996de4

7 files changed

Lines changed: 760 additions & 64 deletions

File tree

lib/hex/tar.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ defmodule Hex.Tar do
1414
filename -> String.to_charlist(filename)
1515
end)
1616

17-
case :mix_hex_tarball.create(metadata, files) do
17+
config =
18+
:mix_hex_core.default_config()
19+
|> Map.put(:tarball_files_root, File.cwd!() |> String.to_charlist())
20+
21+
case :mix_hex_tarball.create(metadata, files, config) do
1822
{:ok, %{tarball: tarball} = result} ->
1923
if output != :memory, do: File.write!(output, tarball)
2024
result

src/mix_hex_core.erl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@
6868
%% * `tarball_max_uncompressed_size' - Maximum size of uncompressed package tarball, defaults to
6969
%% `134_217_728' (128 MiB). Set to `infinity' to not enforce the limit.
7070
%%
71+
%% * `tarball_files_root' - Root directory for source files when creating tarballs.
72+
%% Required for filesystem source paths, which must be relative and must resolve inside
73+
%% this root after following symlinks. Set to `undefined' when all tarball contents are
74+
%% provided as binaries and no filesystem source paths are used (default: `undefined').
75+
%%
7176
%% * `docs_tarball_max_size' - Maximum size of docs tarball, defaults to
7277
%% `16_777_216' (16 MiB). Set to `infinity' to not enforce the limit.
7378
%%
@@ -110,6 +115,7 @@
110115
repo_verify => boolean(),
111116
repo_verify_origin => boolean(),
112117
send_100_continue => boolean(),
118+
tarball_files_root => file:filename() | undefined,
113119
tarball_max_size => pos_integer() | infinity,
114120
tarball_max_uncompressed_size => pos_integer() | infinity,
115121
docs_tarball_max_size => pos_integer() | infinity,
@@ -136,6 +142,7 @@ default_config() ->
136142
repo_verify => true,
137143
repo_verify_origin => true,
138144
send_100_continue => true,
145+
tarball_files_root => undefined,
139146
tarball_max_size => 16 * 1024 * 1024,
140147
tarball_max_uncompressed_size => 128 * 1024 * 1024,
141148
docs_tarball_max_size => 16 * 1024 * 1024,

0 commit comments

Comments
 (0)