Skip to content

Commit

Permalink
Change to W3C limits
Browse files Browse the repository at this point in the history
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
  • Loading branch information
bboreham committed Mar 17, 2021
1 parent e70f649 commit ad05894
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions propagation.go
Expand Up @@ -215,11 +215,10 @@ func (p *BinaryPropagator) Inject(
return nil
}

// These are intended to be unimaginably high: above this number we declare
// the data is corrupted, to protect against running out of memory
// W3C limits https://github.com/w3c/baggage/blob/master/baggage/HTTP_HEADER_FORMAT.md#limits
const (
maxBinaryBaggage = 1024 * 1024
maxBinaryValueLen = 100 * 1024 * 1024
maxBinaryBaggage = 180
maxBinaryNameValueLen = 4096
)

// Extract implements Extractor of BinaryPropagator
Expand Down Expand Up @@ -265,9 +264,6 @@ func (p *BinaryPropagator) Extract(abstractCarrier interface{}) (SpanContext, er
if err := binary.Read(carrier, binary.BigEndian, &keyLen); err != nil {
return emptyContext, opentracing.ErrSpanContextCorrupted
}
if keyLen > maxBinaryValueLen {
return emptyContext, opentracing.ErrSpanContextCorrupted
}
buf.Reset()
buf.Grow(int(keyLen))
if n, err := io.CopyN(buf, carrier, int64(keyLen)); err != nil || int32(n) != keyLen {
Expand All @@ -278,7 +274,7 @@ func (p *BinaryPropagator) Extract(abstractCarrier interface{}) (SpanContext, er
if err := binary.Read(carrier, binary.BigEndian, &valLen); err != nil {
return emptyContext, opentracing.ErrSpanContextCorrupted
}
if valLen > maxBinaryValueLen {
if keyLen+valLen > maxBinaryNameValueLen {
return emptyContext, opentracing.ErrSpanContextCorrupted
}
buf.Reset()
Expand Down

0 comments on commit ad05894

Please sign in to comment.