Skip to content
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

Integer overflow when using >=4096 buffers in IoUring setup_buf_ring #19848

Open
karlbohlmark opened this issue May 3, 2024 · 0 comments
Open
Labels
bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@karlbohlmark
Copy link
Contributor

Zig Version

0.13.0-dev.46+3648d7df1

Steps to Reproduce and Observed Behavior

pub fn main() !void {
    var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){};
    const allocator = gpa.allocator();
    var ring = IoUring.init(256, 0) catch |err| {
        std.debug.print("Failed to initialize io_uring: {s}\n", .{@errorName(err)});
        return;
    };
    defer IoUring.deinit(&ring);
    const buffer_size = 1536;
    const num_buffers = 4096;
    const group_buffers = try allocator.alignedAlloc(u8, std.mem.page_size, buffer_size * num_buffers);
    _ = BufferGroup.init(
        &ring,
        1,
        group_buffers,
        buffer_size,
        num_buffers,
    ) catch |err| switch (err) {
        error.ArgumentsInvalid => return error.KernelTooOld,
        else => return err,
    };
}
thread 134544 panic: integer overflow
/home/karboh/.zvm/master/lib/std/os/linux/IoUring.zig:1562:31: 0x104d2d3 in setup_buf_ring (main)
    const mmap_size = entries * @sizeOf(linux.io_uring_buf);
                              ^
/home/karboh/.zvm/master/lib/std/os/linux/IoUring.zig:1482:38: 0x104d4df in init (main)
        const br = try setup_buf_ring(ring.fd, buffers_count, group_id);
                                     ^
/home/karboh/test/src/main.zig:18:25: 0x104dacb in main (main)
    _ = BufferGroup.init(
                        ^
/home/karboh/.zvm/master/lib/std/start.zig:511:37: 0x104acdf in posixCallMainAndExit (main)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x0 in ??? (???)
Aborted (core dumped)

Expected Behavior

According to the liburing docs: "The maximum size allowed is 2^15 (32768)"

@karlbohlmark karlbohlmark added the bug Observed behavior contradicts documented or intended behavior label May 3, 2024
@Vexu Vexu added the standard library This issue involves writing Zig code for the standard library. label May 3, 2024
@Vexu Vexu added this to the 0.13.0 milestone May 3, 2024
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 standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

2 participants