Skip to content

Core Kafka binary reader decodes unrelated binary headers as UTF-8 #306

Closed

Description

@zhanghao0806

The core Kafka binding decodes every header value as UTF-8 before deciding whether it belongs to CloudEvents. An unrelated application header containing binary bytes therefore prevents an otherwise valid event from being read.

Reproduced on main with both from_binary and from_kafka:

from cloudevents.core.bindings.kafka import KafkaMessage, from_binary
from cloudevents.core.formats.json import JSONFormat

message = KafkaMessage(
    headers={
        "ce_specversion": b"1.0", "ce_id": b"123",
        "ce_type": b"example.created", "ce_source": b"/example",
        "content-type": b"application/json", "correlation-bin": b"\xff\x00\xfe",
    },
    key=None,
    value=b'{"message":"hello"}',
)
from_binary(message, JSONFormat())  # UnicodeDecodeError

Expected: ignore unrelated headers when extracting CloudEvents attributes. Invalid UTF-8 in ce_* and content-type headers should still be rejected.

A focused change is to decode a value only after recognizing its header name. Regression tests reproduce the failure through both public readers.

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