zig icon indicating copy to clipboard operation
zig copied to clipboard

`zig fetch` on zip archives does not ignore errors for files not in `build.zig.zon` paths

Open ianprime0509 opened this issue 6 months ago • 1 comments

Zig Version

0.15.0-dev.480+49c731805

Steps to Reproduce and Observed Behavior

Ensure the Zig global cache directory is located on a filesystem which does not allow the character : in filenames. On Linux, this can be accomplished by creating and mounting a FAT32 filesystem:

fallocate -l 1G fat32.fs
mkfs.fat -F32 fat32.fs
mkdir fat32.mnt
sudo mount -o rw,umask=0000 fat32.fs fat32.mnt
export ZIG_GLOBAL_CACHE_DIR=fat32.mnt

On Windows, this should already be the case with the default NTFS filesystem. Then, run the following command:

$ zig fetch https://github.com/ianprime0509/pathological-packages/archive/e945a092051ea267a5af2655525cbed0d7d5b901.zip
error: zip extract failed: BadPathName

Expected Behavior

The package should be fetched successfully, as the problematic file is not listed in paths in build.zig.zon. Fetching using a tar.gz URL or Git URL produces this expected behavior:

$ zig fetch https://github.com/ianprime0509/pathological-packages/archive/e945a092051ea267a5af2655525cbed0d7d5b901.tar.gz
illegal_file_name-0.0.0-Jk3MdE0AAAA6Vv0NmnZkYPYNarGw6NVXpWHFitmwuR6Y
$ zig fetch git+https://github.com/ianprime0509/pathological-packages#e945a092051ea267a5af2655525cbed0d7d5b901
illegal_file_name-0.0.0-Jk3MdE0AAAA6Vv0NmnZkYPYNarGw6NVXpWHFitmwuR6Y

ianprime0509 avatar May 12 '25 16:05 ianprime0509

This is because std.tar continues after the error when diagnostics is set:

https://github.com/ziglang/zig/blob/518105471e145c90809fb2f5baa53cd08bde31aa/lib/std/tar.zig#L657-L666

while std.zip just uses try directly:

https://github.com/ziglang/zig/blob/518105471e145c90809fb2f5baa53cd08bde31aa/lib/std/zip.zig#L539-L548

So one possible fix would be to add a unable_to_create_file diagnostic to std.zip a la std.tar.

squeek502 avatar May 14 '25 04:05 squeek502