Skip to content

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

@squeek502

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions