Skip to content

Commit 8165c98

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 8165c98

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ 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("Chained exception for snapshot={} is out of bounds: {}/{}", snapshot.getId(), chainedExceptionIdx, chainedExceptions.size());
152+
continue;
153+
}
149154
Throwable currentEx = chainedExceptions.get(snapshot.getChainedExceptionIdx());
150155
int[] mapping = createThrowableMapping(currentEx, t);
151156
StackTraceElement[] innerTrace = currentEx.getStackTrace();

0 commit comments

Comments
 (0)