Skip to content

Dispatcher panics when a failed delivery returns a response body larger than 768 bytes #9504

Description

@RaphaelFakhri

Describe the bug
When a subscriber or trigger destination returns a non-2xx response with a body longer than 768 bytes, and the delivery has a dead letter sink (or a reply), the dispatcher panics with runtime error: index out of range in encoding/base64.(*Encoding).Encode.

dispatchExecutionInfoTransformers in pkg/kncloudevents/event_dispatcher.go caps the destination buffer at KnativeErrorDataExtensionMaxLength (1024) but encodes the whole response body into it:

encodedLen := base64.StdEncoding.EncodedLen(bodyLen)
if encodedLen > attributes.KnativeErrorDataExtensionMaxLength {
	encodedLen = attributes.KnativeErrorDataExtensionMaxLength
}
encodedBuf := make([]byte, encodedLen)
base64.StdEncoding.Encode(encodedBuf, httpResponseBody)

base64.Encode always writes EncodedLen(len(src)) bytes, so it panics if the buffer is shorter than that.

Effects:

  • In the in-memory channel dispatcher, the fanout runs each subscription in its own goroutine, so the panic is not recovered and the dispatcher process exits.
  • In the broker filter, net/http recovers the panic, the connection is dropped, and the event never reaches the dead letter sink.

Expected behavior
The event goes to the dead letter sink, and knativeerrordata holds the base64-encoded response body truncated to 1024 characters.

To Reproduce

  1. Create a Trigger or Subscription with delivery.deadLetterSink set.
  2. Point the subscriber at a service that returns HTTP 500 with a body of 2000 bytes (for example, an HTML error page).
  3. Send an event. The dispatcher logs panic: runtime error: index out of range and the dead letter sink receives nothing.

The unit test case invalid destination with a large response body and delivery option in TestSendEvent reproduces this on main:

panic: runtime error: index out of range [3] with length 0
encoding/base64.(*Encoding).Encode(...)
knative.dev/eventing/pkg/kncloudevents.dispatchExecutionInfoTransformers(...)
	pkg/kncloudevents/event_dispatcher.go:593

Knative release version
main (2153953). The same code has been in place since at least the kncloudevents refactor (#7092).

Additional context
Bodies of 768 bytes or fewer are not affected, because their encoded length fits in the buffer.

Activity

  1. amarkdotdev commented on Nov 3, 2026

    @amarkdotdev

    Opened #9507 for this. /assign

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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions