Skip to content

std.fs.path.resolveWindows trips index-out-of-bounds for certain drive-relative paths #25703

Description

@squeek502

Zig Version

0.16.0-dev.747+493ad58ff

Steps to Reproduce and Observed Behavior

I think this test case should pass if added to the resolveWindows test in std/fs/path.zig:

try testResolveWindows(&[_][]const u8{ "c:foo", "bar" }, "C:foo\\bar");

However, currently that will result in:

thread 223411 panic: index out of bounds: index 0, len 0
Unwind error at address `/proc/self/exe:0x103fd3d` (unwind info unavailable), remaining frames may be incorrect
/home/ryan/Programming/zig/zig/lib/std/fs/path.zig:492:36: 0x120bf06 in compareDiskDesignators (std.zig)
            return ascii.toUpper(p1[0]) == ascii.toUpper(p2[0]);
                                   ^
/home/ryan/Programming/zig/zig/lib/std/fs/path.zig:618:65: 0x120653d in resolveWindows (std.zig)
                correct_disk_designator = compareDiskDesignators(drive_kind, dd, parsed.disk_designator);
                                                                ^
/home/ryan/Programming/zig/zig/lib/std/fs/path.zig:829:38: 0x1204a78 in testResolveWindows (std.zig)
    const actual = try resolveWindows(testing.allocator, paths);
                                     ^
/home/ryan/Programming/zig/zig/lib/std/fs/path.zig:803:27: 0x1210878 in decltest.resolveWindows (std.zig)
    try testResolveWindows(&[_][]const u8{ "c:foo", "bar" }, "C:foo\\bar");
                          ^
/home/ryan/Programming/zig/zig/lib/compiler/test_runner.zig:240:25: 0x119d650 in mainTerminal (test_runner.zig)
        if (test_fn.func()) |_| {
                        ^
/home/ryan/Programming/zig/zig/lib/compiler/test_runner.zig:69:28: 0x1196b91 in main (test_runner.zig)
        return mainTerminal();
                           ^
/home/ryan/Programming/zig/zig/lib/std/start.zig:618:22: 0x1190dd9 in callMain (std.zig)
            root.main();
                     ^
/home/ryan/Programming/zig/zig/lib/std/start.zig:232:5: 0x1190811 in _start (std.zig)
    asm volatile (switch (native_arch) {
    ^

The problem is that c:foo (a drive-relative path) is given as the first path, which it's currently not equipped to handle.

Note

To resolve this into a drive-absolute path, it would be necessary to get the CWD for the given drive, which is not something resolve wants to do (#13613).

Note also that there's a test case that uses a drive-relative path (but only after a drive-absolute path) that succeeds here:

try testResolveWindows(&[_][]const u8{ "d:/ignore", "d:some/dir//" }, "D:\\ignore\\some\\dir");

Expected Behavior

No panic, and the test to succeed. I think it makes the most sense for the result to be a drive-relative path to continue not needing to actually get the CWD.

Activity

  1. added
    bugObserved behavior contradicts documented or intended behavior
    standard libraryThis issue involves writing Zig code for the standard library.
    on Oct 26, 2025
  2. changed the title [-]std.fs.path.resolveWindows trips index-out-of-bounds for certain "rooted" (drive-CWD-relative) paths[/-] [+]std.fs.path.resolveWindows trips index-out-of-bounds for certain drive-relative paths[/+] on Oct 26, 2025
  3. added 6 commits that reference this issue on Nov 21, 2025
    89c12a8
    4eec10b
    d2aa453
    2b4af85
    b65f391
    59b8bed
  4. added this to the 0.16.0 milestone on Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavioros-windowsMicrosoft Windowsstandard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions