StringIndexOutOfBoundsException when traceparent is too small · Issue #2038 · census-instrumentation/opencensus-java · GitHub
Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

StringIndexOutOfBoundsException when traceparent is too small #2038

Open

Description

@alysyk

Please answer these questions before submitting a bug report.

What version of OpenCensus are you using?

0.24.0

What JVM are you using (java -version)?

1.8

What did you do?

When using OcHttpServletFilter and the trace id is too short, TraceContextFormat's argument check, will throw a StringIndexOutOfBoundsException which is not caught.

What did you expect to see?

TraceContextFormat throws a SpanContextParseException and does not throw an uncaught exception

What did you see instead?

Uncaught StringIndexOutOfBoundsException at the application level

Additional context

By re-ordering to check length first, this issue should be caught

checkArgument(
  (traceparent.length() == TRACEPARENT_HEADER_SIZE || (traceparent.length() > TRACEPARENT_HEADER_SIZE && traceparent.charAt(TRACEPARENT_HEADER_SIZE) == TRACEPARENT_DELIMITER))
  && traceparent.charAt(TRACE_OPTION_OFFSET - 1) == TRACEPARENT_DELIMITER 
  && traceparent.charAt(SPAN_ID_OFFSET - 1) == TRACEPARENT_DELIMITER,
  "Missing or malformed TRACEPARENT.");

Activity

  1. dengliming commented on Jul 26, 2020

    @dengliming

    You were right. and traceparent.charAt(TRACE_OPTION_OFFSET - 1) == TRACEPARENT_DELIMITER this line is duplicated.

  2. dengliming commented on Aug 11, 2020

    @dengliming

    @alysyk Can you share your reproducing code here?

  3. alysyk commented on Sep 27, 2021

    @alysyk
    Author

    If traceparent is an empty string, you'll throw a StringIndexOutOfBoundsException.

  4. Bharath-Ganesh commented on Apr 1, 2023

    @Bharath-Ganesh

    I see that the aforementioned issue was raised a couple of years back. Can I take this over if it hasn't been resolved yet?
    /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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions