Skip to content

Commit 95e8cb0

Browse files
committed
Fix possible IndexOutOfBoundsException
if chainedExceptionIndex stored into the snapshot is incorrect, it can lead to an IndexOutOfBoundsException. Protect against it
1 parent 425276d commit 95e8cb0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/AbstractExceptionDebugger.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ private void processSnapshotsAndSetTags(
146146
int maxSnapshotSize = Math.min(snapshots.size(), maxCapturedFrames);
147147
for (int i = 0; i < maxSnapshotSize; i++) {
148148
Snapshot snapshot = snapshots.get(i);
149+
int chainedExceptionIdx = snapshot.getChainedExceptionIdx();
150+
if (chainedExceptionIdx >= chainedExceptions.size()) {
151+
LOGGER.debug(
152+
"Chained exception for snapshot={} is out of bounds: {}/{}",
153+
snapshot.getId(),
154+
chainedExceptionIdx,
155+
chainedExceptions.size());
156+
continue;
157+
}
149158
Throwable currentEx = chainedExceptions.get(snapshot.getChainedExceptionIdx());
150159
int[] mapping = createThrowableMapping(currentEx, t);
151160
StackTraceElement[] innerTrace = currentEx.getStackTrace();

0 commit comments

Comments
 (0)