From 0c27069cca97c081e288c695d2fa1d51ade7c82e Mon Sep 17 00:00:00 2001 From: chrislu Date: Fri, 17 Oct 2025 15:50:49 -0700 Subject: [PATCH] Validate that the unmarshaled RecordValue has valid field data --- weed/mq/kafka/protocol/fetch.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/weed/mq/kafka/protocol/fetch.go b/weed/mq/kafka/protocol/fetch.go index 94a07c671..a2dbcc8e6 100644 --- a/weed/mq/kafka/protocol/fetch.go +++ b/weed/mq/kafka/protocol/fetch.go @@ -1146,6 +1146,13 @@ func (h *Handler) decodeRecordValueToKafkaMessage(topicName string, recordValueB return recordValueBytes } + // Validate that the unmarshaled RecordValue has valid field data + // Protobuf unmarshal is lenient and can succeed with garbage data for random bytes + // If Fields is nil or empty, this is not a valid RecordValue - return raw bytes + if recordValue.Fields == nil || len(recordValue.Fields) == 0 { + return recordValueBytes + } + // If schema management is enabled, re-encode the RecordValue to Confluent format if h.IsSchemaEnabled() { if encodedMsg, err := h.encodeRecordValueToConfluentFormat(topicName, recordValue); err == nil {