Skip to content

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

Closed
@tomasz-lisowski

Description

@tomasz-lisowski

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions