census-instrumentation / opencensus-go

A stats collection and distributed tracing framework
http://opencensus.io
Apache License 2.0
2.05k stars 326 forks source link

Panic when x-b3-spanid exceeds 16 characters #1205

Closed aopat closed 4 years ago

aopat commented 4 years ago

Please answer these questions before submitting a bug report.

What version of OpenCensus are you using?

0.22.3

What version of Go are you using?

go1.14 darwin/amd64

What did you do?

If possible, provide a recipe for reproducing the error.

  1. Setup a server using ochttp.Handler with Propagation: &b3.HTTPFormat{}
  2. Sent a request to the server with an x-b3-spanid header consisting of 18 character string of hex-numeric characters (eg. 1234567812345678aa)

What did you expect to see?

Expected the trace/span headers to be considered invalid, so a new trace would be initiated

What did you see instead?

panic

panic: runtime error: slice bounds out of range [-1:]

goroutine 1 [running]:
go.opencensus.io/plugin/ochttp/propagation/b3.ParseSpanID(0x132088c, 0x12, 0x0, 0x132088c)
        /Users/andrew/dev/opencensus-go/plugin/ochttp/propagation/b3/b3.go:98 +0x14e
go.opencensus.io/plugin/ochttp/propagation/b3.(*HTTPFormat).SpanContextFromRequest(0x15adcf8, 0xc00022a000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x131d476)
        /Users/andrew/dev/opencensus-go/plugin/ochttp/propagation/b3/b3.go:53 +0xd9
go.opencensus.io/plugin/ochttp.(*Handler).extractSpanContext(0xc0002dff28, 0xc00022a000, 0x0, 0x0, 0x0, 0x0, 0x0, 0x131f21c)
        /Users/andrew/dev/opencensus-go/plugin/ochttp/server.go:146 +0x7a
go.opencensus.io/plugin/ochttp.(*Handler).startTrace(0xc0002dff28, 0x1389a20, 0xc00013a740, 0xc00022a000, 0x38, 0xc00013a740)
        /Users/andrew/dev/opencensus-go/plugin/ochttp/server.go:113 +0x133
go.opencensus.io/plugin/ochttp.(*Handler).ServeHTTP(0xc0002dff28, 0x1389a20, 0xc00013a740, 0xc00022a000)
        /Users/andrew/dev/opencensus-go/plugin/ochttp/server.go:83 +0x9c
main.main()
        /Users/andrew/dev/opencensus-go/tests/invalid-id.go:28 +0x326
exit status 2

Additional context

This also affects x-b3-traceid headers exceeding 32 characters. span/trace headers need to have an even number of hex characters to produce this issue. Otherwise they correctly fail the hex decoding.