Skip to content

UDP receive buffers grow beyond the maximum IPv4 payload #1695

Closed

Description

@oxura

UDP.bind is IPv4-only, but UDP receive currently sizes its buffer from the caller's max: the JS backend reserves max bytes, and C reserves min(max, INT32_MAX) plus one spare byte. An IPv4 UDP payload cannot exceed 65,535 - 20 - 8 = 65,507 bytes.

On main e5527d5, I sent a real one-byte loopback datagram and received it with max=1,048,576. A typed-array constructor trace records a 1,048,576-byte JS buffer; a native build linked with --wrap=malloc records a 1,048,577-byte allocation. Both consumers receive x successfully. This measures requested buffer sizes, not RSS; I did not try allocating 4 GiB.

Bounding the payload capacity to min(max, 65507) reduces those requests to 65,507 and 65,508 bytes with the same received data. max=0 must still fail without consuming a datagram; smaller positive limits must keep their existing truncation behavior. This applies to the text/byte and blocking/try receive variants sharing these helpers.

Observed with Bun 1.3.13 and clang 22 on Linux x86-64.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions