kristoff-it/bork

HttpHeadersExceededSizeLimit when authenticating oauth.

Closed this issue · 2 comments

I get the following when I attempt to authorize with bork. It seems to originate from src/network/twitch/auth.zig and is related to the following lines of code:

var header_buffer: [1024]u8 = undefined;
accept: while (true) {
var res = try server.accept(.{
.allocator = gpa,
.header_strategy = .{ .static = &header_buffer },
});

Current zig header_strategy defaults to dynamic at 8192:

    header_strategy: HeaderStrategy = .{ .dynamic = 8192 },

When I simply comment out header_buffer being passed in I successfully am able to handle the headers, but then I get the following error:

Waiting...
Authenticating with Twitch...
fish: Job 1, 'bork start' terminated by signal SIGSEGV (Address boundary error)

Changing header_buffer to 2048 successfully fit my headers and avoided my address boundary error! I'll push a PR and link this issue with the change. Feel free to decline the PR if you prefer another approach.

Would love to see the segfault being investigated a little. Merged the PR in the meantime.

//var header_buffer: [2048]u8 = undefined;
            //.header_strategy = .{ .static = &header_buffer },

This is the stacktrace if the code doesn't use an explicit header_strategy:

Segmentation fault at address 0x76d4deea1013
/home/allison/zig/0.12.0-dev.2543+9eda6ccef/files/lib/compiler_rt/memcpy.zig:19:21: 0x15a80bc in memcpy (compiler_rt)
            d[0] = s[0];
                    ^
/home/allison/zig/0.12.0-dev.2543+9eda6ccef/files/lib/std/io/fixed_buffer_stream.zig:70:57: 0x11de41b in write (bork)
            @memcpy(self.buffer[self.pos..][0..n], bytes[0..n]);
                                                        ^
/home/allison/zig/0.12.0-dev.2543+9eda6ccef/files/lib/std/io/writer.zig:17:27: 0x11aeebb in write (bork)
            return writeFn(self.context, bytes);
                          ^
/home/allison/zig/0.12.0-dev.2543+9eda6ccef/files/lib/std/io/writer.zig:23:40: 0x1144784 in writeAll (bork)
                index += try self.write(bytes[index..]);
                                       ^
/home/allison/zig/0.12.0-dev.2543+9eda6ccef/files/lib/std/fmt.zig:1025:28: 0x11ae065 in formatBuf__anon_13542 (bork)
        try writer.writeAll(buf);
                           ^
/home/allison/zig/0.12.0-dev.2543+9eda6ccef/files/lib/std/fmt.zig:636:37: 0x11877a1 in formatType__anon_13276 (bork)
                    return formatBuf(value, options, writer);
                                    ^
/home/allison/zig/0.12.0-dev.2543+9eda6ccef/files/lib/std/fmt.zig:184:23: 0x11876ef in format__anon_13271 (bork)
        try formatType(
                      ^
/home/allison/zig/0.12.0-dev.2543+9eda6ccef/files/lib/std/fmt.zig:1989:15: 0x111f66c in bufPrint__anon_10414 (bork)
    try format(fbs.writer(), fmt, args);
              ^
/home/allison/zig/0.12.0-dev.2543+9eda6ccef/files/lib/std/fmt.zig:2010:20: 0x10dffb9 in allocPrint__anon_5353 (bork)
    return bufPrint(buf, fmt, args) catch |err| switch (err) {
                   ^
/brrr/git/bork/src/network/twitch/auth.zig:68:48: 0x10df838 in authenticateToken (bork)
    const header_oauth = try std.fmt.allocPrint(
                                               ^
/brrr/git/bork/src/network/twitch/auth.zig:259:35: 0x10e5cc5 in createToken (bork)
    const auth = authenticateToken(gpa, token) catch |err| {
                                  ^
/brrr/git/bork/src/network/twitch/auth.zig:36:35: 0x10e6b31 in get (bork)
                return createToken(gpa, config_base, .new);
                                  ^
/brrr/git/bork/src/main.zig:105:30: 0x110cdba in borkStart (bork)
    const auth = try Auth.get(gpa, config_base);
                             ^
/brrr/git/bork/src/main.zig:81:32: 0x1117402 in main (bork)
        .start => try borkStart(gpa),
                               ^
/home/allison/zig/0.12.0-dev.2543+9eda6ccef/files/lib/std/start.zig:585:37: 0x10dc9e5 in posixCallMainAndExit (bork)
            const result = root.main() catch |err| {
                                    ^
/home/allison/zig/0.12.0-dev.2543+9eda6ccef/files/lib/std/start.zig:253:5: 0x10dc4d1 in _start (bork)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0x1 in ??? (???)
Unwind information for `???:0x1` was not available, trace may be incomplete

fish: Job 1, './zig-out/bin/bork start' terminated by signal SIGABRT (Abort)