Skip to content

Crash in std.crypto.tls.Client.readvAdvanced. #15673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tomasz-lisowski opened this issue May 12, 2023 · 1 comment
Closed

Crash in std.crypto.tls.Client.readvAdvanced. #15673

tomasz-lisowski opened this issue May 12, 2023 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@tomasz-lisowski
Copy link
Contributor

tomasz-lisowski commented May 12, 2023

Zig Version

0.11.0-dev.3105+e46d7a369

Steps to Reproduce and Observed Behavior

This is the example copied from: zig/test/standalone/http.zig with the offending URL pasted in, instead of the local target. I don't see an easy way to record and include the exact behavior of the server for perfect repeatability. Best I can do is to archive the page although I doubt that helps much.

pub fn main() !void {
    var alloc_gp = std.heap.GeneralPurposeAllocator(.{}){};
    var alloc = alloc_gp.allocator();
    defer _ = alloc_gp.deinit();

    var client = std.http.Client{ .allocator = alloc };
    defer client.deinit();

    var h = std.http.Headers{ .allocator = alloc };
    defer h.deinit();

    const location = try std.fmt.allocPrint(alloc, "https://apps.apple.com/us/app/google-chrome/id535886823", .{});
    defer alloc.free(location);
    const uri = try std.Uri.parse(location);

    std.log.info("{s}", .{location});
    var req = try client.request(.GET, uri, h, .{});
    defer req.deinit();

    try req.start();
    try req.wait();

    const body = try req.reader().readAllAlloc(alloc, 16_777_216);
    defer alloc.free(body);

    std.log.info("Body: {s}.", .{body});
}

This causes:

thread 1234567 panic: @memcpy arguments have non-equal lengths
/zig/std/crypto/tls/Client.zig:1062:25: 0x392ebb in readvAdvanced__anon_9848
            @memcpy(frag[0..in], first);

When replacing in with first.len causes:

thread 1234567 panic: @memcpy arguments alias
/zig/std/crypto/tls/Client.zig:1062:25: 0x392f17 in readvAdvanced__anon_9848
            @memcpy(frag[0..first.len], first);

Replacing the @memcpy with std.mem.copyForwards gives:

thread 1234567 panic: index out of bounds: index 16384, len 14332
/zig/std/crypto/tls/Client.zig:1180:45: 0x396fc4 in readvAdvanced__anon_9848
                                @memcpy(dest[0..msg.len], msg);

Expected Behavior

The body of the web page inside body.

@tomasz-lisowski tomasz-lisowski added the bug Observed behavior contradicts documented or intended behavior label May 12, 2023
@tomasz-lisowski tomasz-lisowski changed the title Crash in std:crypto.tls.Client.readvAdvanced. Crash in std.crypto.tls.Client.readvAdvanced. May 12, 2023
@Vexu
Copy link
Member

Vexu commented May 12, 2023

Duplicate of #15590

@Vexu Vexu marked this as a duplicate of #15590 May 12, 2023
@Vexu Vexu closed this as completed May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants