Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic caused by invalid spanId with b3 propagator #5754

Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Custom attributes targeting metrics recorded by the `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` are not ignored anymore. (#5129)
- Use `c.FullPath()` method to set `http.route` attribute in `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin`. (#5734)
- The double setup in `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace/example` that caused duplicate traces. (#5564)
- Out-of-bounds panic in case of invalid span ID in `go.opentelemetry.io/contrib/propagators/b3`. (#5754)

### Deprecated

Expand Down
3 changes: 3 additions & 0 deletions propagators/b3/b3_propagator.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ func extractSingle(ctx context.Context, contextHeader string) (context.Context,
}
pos += separatorWidth // {traceID}-

if headerLen < pos+spanIDWidth {
return ctx, empty, errInvalidSpanIDValue
}
scc.SpanID, err = trace.SpanIDFromHex(contextHeader[pos : pos+spanIDWidth])
if err != nil {
return ctx, empty, errInvalidSpanIDValue
Expand Down
12 changes: 12 additions & 0 deletions propagators/b3/b3_propagator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ func TestExtractSingle(t *testing.T) {
{"3", trace.SpanContextConfig{}, errInvalidSampledByte, false, false},
{"000000000000007b", trace.SpanContextConfig{}, errInvalidScope, false, false},
{"000000000000007b00000000000001c8", trace.SpanContextConfig{}, errInvalidScope, false, false},
// TraceID with illegal length
{
"000001c8-000000000000007b",
trace.SpanContextConfig{},
errInvalidTraceIDValue, false, false,
},
// SpanID with illegal length
{
"000000000000007b00000000000001c8-0000007b",
trace.SpanContextConfig{},
errInvalidSpanIDValue, false, false,
},
// Support short trace IDs.
{
"00000000000001c8-000000000000007b",
Expand Down