diff --git a/brave/propagation-aws/src/main/java/brave/propagation/aws/AWSExtractor.java b/brave/propagation-aws/src/main/java/brave/propagation/aws/AWSExtractor.java index ffbf9c1b..a5736022 100644 --- a/brave/propagation-aws/src/main/java/brave/propagation/aws/AWSExtractor.java +++ b/brave/propagation-aws/src/main/java/brave/propagation/aws/AWSExtractor.java @@ -124,6 +124,7 @@ public TraceContextOrSamplingFlags extract(R request) { } else if (c >= 'a' && c <= 'f') { traceIdHigh |= c - 'a' + 10; } else { + traceIdHigh = 0L; break OUTER; // invalid format } } @@ -136,6 +137,8 @@ public TraceContextOrSamplingFlags extract(R request) { } else if (c >= 'a' && c <= 'f') { traceId |= c - 'a' + 10; } else { + traceIdHigh = 0L; + traceId = 0L; break OUTER; // invalid format } } diff --git a/brave/propagation-aws/src/test/java/brave/propagation/aws/AWSPropagationTest.java b/brave/propagation-aws/src/test/java/brave/propagation/aws/AWSPropagationTest.java index a013ada3..4975c0f0 100644 --- a/brave/propagation-aws/src/test/java/brave/propagation/aws/AWSPropagationTest.java +++ b/brave/propagation-aws/src/test/java/brave/propagation/aws/AWSPropagationTest.java @@ -296,4 +296,18 @@ public void extract_skips_really_malformed() { assertThat(extractor.extract(carrier).samplingFlags()).isEqualTo(SamplingFlags.EMPTY); } + + @Test + public void extract_malformed_check_not_throws_exception_different_length() { + carrier.put("x-amzn-trace-id", "Root=1-1373cbb-77f4b48ed7ff3eebbd62b5e01;Parent=1a4e96536a3ff131;Sampled=0"); + + assertThat(extractor.extract(carrier).samplingFlags()).isEqualTo(SamplingFlags.EMPTY); + } + + @Test + public void extract_malformed_throws_exception_not_hexadecimal_value() { + carrier.put("x-amzn-trace-id", "Root=1-1z373cbb-77f4b48ed7ff3eebbd62b5e01;Parent=1a4e96536a3ff131;Sampled=0"); + + assertThat(extractor.extract(carrier).samplingFlags()).isEqualTo(SamplingFlags.EMPTY); + } }