Skip to content

Skip tarball root directory entries instead of crashing - #252

Merged
ericmj merged 1 commit into
mainfrom
ericmj/tarball-root-entries
Oct 22, 2026
Merged

ericmj merged 1 commit into
mainfrom
ericmj/tarball-root-entries

Conversation

@ericmj

@ericmj ericmj commented Oct 22, 2026

Copy link
Copy Markdown
Member

hex_tarball:create/3 and hex_tarball:create_docs/2 crash with a function_clause error in lists:seq(1, -1) when a file name resolves to the root of the tarball, such as ".", "./" or "a/..". Since #228, directories with files under them are dropped by computing each name's parent directories, and a name with no path components breaks that computation. rebar3_hex passes {".", DocDir} for the docs directory itself, so its docs builds fail with hex_core v0.20.0 and later (erlef/rebar3_hex#387 filters the entry out as a workaround).

A directory named after the root is now skipped, which gives the same tarball as v0.19.0 for a non-empty directory. A regular file or symlink with such a name returns {error, {tarball, {unsafe_path, Name}}}. v0.19.0 wrote it as a member named ., which failed to unpack to disk with eisdir.

Fixes #251

hex_tarball:create/3 and hex_tarball:create_docs/2 crashed with a
function_clause error in lists:seq/2 when a file name resolved to the
root of the tarball, such as ".", "./" or "a/..". Since
#228 directories with files under
them are dropped by computing each name's parent directories, and a name
with no path components called lists:seq(1, -1). rebar3_hex passes
{".", DocDir} for the docs directory itself, so its docs builds fail
with hex_core v0.20.0 and later.

A directory named after the root is now skipped, which gives the same
tarball as v0.19.0 for a non-empty directory. A regular file or symlink
with such a name returns an unsafe_path error. v0.19.0 wrote it as a
member named ".", which failed to unpack to disk with eisdir.

Fixes #251
@ericmj
ericmj force-pushed the ericmj/tarball-root-entries branch from 71e0b60 to bb03c53 Compare October 22, 2026 09:26
@ericmj
ericmj merged commit bee8659 into main Oct 22, 2026
10 checks passed
@ericmj
ericmj deleted the ericmj/tarball-root-entries branch October 22, 2026 09:35
This was referenced Oct 22, 2026
ericmj added a commit to hexpm/hex that referenced this pull request Oct 22, 2026
hex_core v0.21.1 skips a package file whose name resolves to the root of
the tarball when it's a directory, instead of crashing with
FunctionClauseError in :lists.seq/2
(hexpm/hex_core#252). Since hex_core v0.20.0 was
vendored, mix hex.build crashed this way when the package files included
the project directory, such as files: ["."], because expand_paths lists
the directory itself as ".". Add a test that builds a package with
files: ["."].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: hex_tarball:create_docs/3 can not handle when cwd is in the file list.

1 participant