Repository navigation
Closed
Labels
bugObserved behavior contradicts documented or intended behavior
Description
Zig Version
0.11.0-dev.2702+a86759984
Steps to Reproduce and Observed Behavior
Attempting to run zig build on Andrew's groovebasin project (https://github.com/andrewrk/groovebasin/tree/zig-pkg) on x86_64 Windows fails with a panic while trying to download the .tar.gz dependency declared in build.zig.zon:
.{
.name = "groovebasin",
.version = "0.0.0",
.dependencies = .{
.groove = .{
.url = "https://github.com/andrewrk/libgroove/archive/045acefe70ad53f730d5250c3699d1191bf33f51.tar.gz",
.hash = "12200f41f9804eb9abff259c5d0d84f27caa0a25e0f72451a0243a806c8f94fdc433",
},
},
}
panic stack trace:
thread 12604 panic: incorrect alignment
C:\Users\Adam\Documents\Zig\zig\lib\std\hash_map.zig:945:100: 0x7ff646837d86 in header (zig.exe.obj)
return @ptrCast(*Header, @ptrCast([*]Header, @alignCast(@alignOf(Header), self.metadata.?)) - 1);
^
C:\Users\Adam\Documents\Zig\zig\lib\std\hash_map.zig:959:31: 0x7ff646297b12 in capacity (zig.exe.obj)
return self.header().capacity;
^
C:\Users\Adam\Documents\Zig\zig\lib\std\hash_map.zig:822:50: 0x7ff645ffef19 in next (zig.exe.obj)
assert(it.index <= it.hm.capacity());
^
C:\Users\Adam\Documents\Zig\zig\lib\std\http\Headers.zig:72:23: 0x7ff645dc67ad in deinit (zig.exe.obj)
while (it.next()) |entry| {
^
C:\Users\Adam\Documents\Zig\zig\lib\std\http\Client.zig:512:40: 0x7ff645dc7b07 in deinit (zig.exe.obj)
req.response.headers.deinit();
^
C:\Users\Adam\Documents\Zig\zig\src\Package.zig:486:25: 0x7ff645dc4447 in fetchAndUnpack (zig.exe.obj)
defer req.deinit();
^
C:\Users\Adam\Documents\Zig\zig\src\Package.zig:282:43: 0x7ff645dcad4c in fetchAndAddDependencies (zig.exe.obj)
const sub_pkg = try fetchAndUnpack(
^
C:\Users\Adam\Documents\Zig\zig\src\main.zig:4397:67: 0x7ff645c16717 in cmdBuild (zig.exe.obj)
const fetch_result = build_pkg.fetchAndAddDependencies(
^
C:\Users\Adam\Documents\Zig\zig\src\main.zig:298:24: 0x7ff645be38dc in mainArgs (zig.exe.obj)
return cmdBuild(gpa, arena, cmd_args);
^
C:\Users\Adam\Documents\Zig\zig\src\main.zig:211:20: 0x7ff645be2a2e in main (zig.exe.obj)
return mainArgs(gpa, arena, args);
^
C:\Users\Adam\Documents\Zig\zig\lib\std\start.zig:508:80: 0x7ff645be4851 in main (zig.exe.obj)
return @call(.always_inline, callMainWithArgs, .{ @intCast(usize, c_argc), @ptrCast([*][*:0]u8, c_argv), envp });
^
???:?:?: 0x7ff647958da4 in ??? (zig.exe)
???:?:?: 0x7ff647958dfb in ??? (zig.exe)
???:?:?: 0x7fffb6357603 in ??? (KERNEL32.DLL)
???:?:?: 0x7fffb81e26a0 in ??? (ntdll.dll)
Expected Behavior
Dependencies should be downloaded without crashing.
Reacted by Ryan Liptak
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behavior
Activity
[-]std.http.Client.do panics with incorrect alignment[/-][+]std.http.Client panics with incorrect alignment while downloading .tar.gz[/+][-]std.http.Client panics with incorrect alignment while downloading .tar.gz[/-][+]std.http.Client panics while iterating through headers[/+]squeek502 commentedon Apr 22, 2023
Same issue when trying to build
zls. Also on Windows. Likely caused by #15299cc @truemedian
EDIT: Looks likely to be a double free:
EDIT#2: Think I tracked it down. In
Package.zig:zig/src/Package.zig
Lines 485 to 490 in 21aa55d
In
dowithinClient.zig:zig/lib/std/http/Client.zig
Lines 707 to 717 in 21aa55d
EDIT#3: Full stacktrace for each
Headers.deinit:EDIT#4: My guess is this is the problem:
zig/lib/std/http/Client.zig
Line 1022 in 21aa55d
since
req.* = new_reqmeans that thedefer req.deinit()inPackage.zigmeans it will try to free thereq.response.headerswhich areundefinedstd.http: Always initialize `response.headers` in Client.request
truemedian commentedon Apr 22, 2023
What's actually missing here is that the redirect code should be
startanddo'ing the new request. Which brings into question the fact this will do the wrong thing for requests that send a payload.std.http: Always initialize `response.headers` in Client.request
nektro commentedon Apr 29, 2023
just hit this on
0.11.0-dev.2889+011bc59e8from adefer std.http.Server.Response.reset(), investigating...edit: server code https://zigbin.io/8e3a70
coratgerl commentedon May 6, 2023
Same issue in
defer std.http.Server.Response.reset()(same code as above) with0.11.0-dev.2939+289234744squeek502 commentedon May 7, 2023
I would open a new issue for
Server.Response. The problem looks similar but the fix might be a bit different.