Skip to content

Commit 78be799

Browse files
authored
Add safety check for TargetSystem encoding limits (#10451)
1 parent b11fcdf commit 78be799

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/InstrumenterIndex.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,14 @@ static boolean decodeModuleHasTargetSystemOverrides(byte flags) {
391391
}
392392

393393
static short encodeTargetSystems(Set<InstrumenterModule.TargetSystem> targetSystems) {
394+
final int allTargetSystemsCount = InstrumenterModule.TargetSystem.values().length;
395+
// Safety check to ensure we don’t overflow the index if additional TargetSystem enums are added
396+
if (allTargetSystemsCount > 16) {
397+
throw new IllegalStateException(
398+
"Using a short will only allow encoding 16 different target systems, but found "
399+
+ allTargetSystemsCount
400+
+ ". Please use a larger data type for encoding/decoding this field.");
401+
}
394402
short ret = 0;
395403
for (InstrumenterModule.TargetSystem ts : targetSystems) {
396404
ret |= (short) (1 << ts.ordinal());

0 commit comments

Comments
 (0)