Skip to content

Commit

Permalink
fix panic in b3 propagator
Browse files Browse the repository at this point in the history
  • Loading branch information
Cirilla-zmh committed Jun 11, 2024
1 parent 8b12e62 commit d7b88ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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
10 changes: 10 additions & 0 deletions propagators/b3/b3_propagator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ func TestExtractSingle(t *testing.T) {
{"000000000000007b", trace.SpanContextConfig{}, errInvalidScope, false, false},
{"000000000000007b00000000000001c8", trace.SpanContextConfig{}, errInvalidScope, false, false},
// Support short trace IDs.
{
"invalid-000000000000007b",
trace.SpanContextConfig{},
errInvalidTraceIDValue, false, false,
},
{
"000000000000007b00000000000001c8-invalid",
trace.SpanContextConfig{},
errInvalidSpanIDValue, false, false,
},
{
"00000000000001c8-000000000000007b",
trace.SpanContextConfig{
Expand Down

0 comments on commit d7b88ed

Please sign in to comment.