Skip to content

zig build system and std.ChildProcess fails if an environment variable contains an invalid UTF-8 #18694

Description

@paperclover

Zig Version

0.12.0-dev.2338+9d5a133f1

Steps to Reproduce and Observed Behavior

I ran into this on accident when trying to narrow a bug in bun. I do not suspect this has any real use case.

$Env:damn = "`u{D834}"
zig init
zig build
error: DanglingSurrogateHalf
C:\Users\dave\scoop\apps\zig-dev\0.12.0-dev.2338+9d5a133f1\lib\std\unicode.zig:469:39: 0xbe2e2a in nextCodepoint (build.exe.obj)
            if (it.i >= it.bytes.len) return error.DanglingSurrogateHalf;
                                      ^
C:\Users\dave\scoop\apps\zig-dev\0.12.0-dev.2338+9d5a133f1\lib\std\unicode.zig:806:12: 0xbe3f6e in utf16leToUtf8Alloc (build.exe.obj)
    while (try it.nextCodepoint()) |codepoint| {
           ^
C:\Users\dave\scoop\apps\zig-dev\0.12.0-dev.2338+9d5a133f1\lib\std\process.zig:280:27: 0xbe5409 in getEnvMap (build.exe.obj)
            const value = try std.unicode.utf16leToUtf8Alloc(allocator, value_w);
                          ^
C:\Users\dave\scoop\apps\zig-dev\0.12.0-dev.2338+9d5a133f1\lib\std\Build.zig:221:17: 0xbe811a in create (build.exe.obj)
    env_map.* = try process.getEnvMap(allocator);
                ^
C:\Users\dave\scoop\apps\zig-dev\0.12.0-dev.2338+9d5a133f1\lib\build_runner.zig:79:21: 0xbf3d80 in main (build.exe.obj)
    const builder = try std.Build.create(
                    ^
error: the following build command failed with exit code 1:
C:\test\zig-cache\o\8bd32588574a7225f4b7ae0f400f442b\build.exe C:\Users\dave\scoop\apps\zig-dev\0.12.0-dev.2338+9d5a133f1\zig.exe C:\test C:\test\zig-cache C:\Users\dave\AppData\Local\zig --seed 0xdac8d76b

Expected Behavior

To ignore or handle this error.

Activity

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 Windows

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions