Skip to content

NewRpcError truncation can split a multi-byte UTF-8 character #1017

Description

@RaphaelFakhri

NewRpcError truncates message (256 bytes) and data (15 KiB) with truncateBytes, which slices the string at a byte offset. When the offset falls inside a multi-byte UTF-8 character, the result is invalid UTF-8.

RpcError.toProto() puts that string in a protobuf string field. proto.Marshal rejects invalid UTF-8, so the error response cannot be sent and the caller does not receive the intended error.

Reproduce

msg := "a" + strings.Repeat("é", 200) // 401 bytes
err := lksdk.NewRpcError(lksdk.RpcApplicationError, msg, nil)
// err.Message ends with a partial rune

Marshalling the resulting livekit.RpcError fails with string field contains invalid UTF-8.

Expected

Truncation stops at the last complete character that fits in the limit.

Activity

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