Skip to content

Commit 27219b7

Browse files
committed
fix(spdx): Avoid running into cycles when computing linkage types
Previously, the function could run into an infinite loop. This has been spotted from reading the code, but has not been observed when ORT executes (yet). Signed-off-by: Frank Viernau <frank.viernau@gmail.com>
1 parent 2482a8e commit 27219b7

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

plugins/reporters/spdx/src/main/kotlin/SpdxDocumentModelMapper.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ private fun SpdxPackage.filterChecksums(wantSpdx23: Boolean): SpdxPackage =
218218
private fun OrtResult.getLinkageTypesForDependencyRelationships():
219219
Map<Pair<Identifier, Identifier>, Set<PackageLinkage>> {
220220
val result = mutableMapOf<Pair<Identifier, Identifier>, MutableSet<PackageLinkage>>()
221+
val visitedNodeReferenceKeys = mutableSetOf<Any>()
221222

222223
// Traverse all non-excluded edges and collect the linkage types used in between any pair of ids.
223224
getProjects(omitExcluded = true, includeSubProjects = true).forEach { project ->
@@ -235,6 +236,11 @@ private fun OrtResult.getLinkageTypesForDependencyRelationships():
235236
while (queue.isNotEmpty()) {
236237
val parent = queue.removeFirst()
237238

239+
when (val key = parent.getInternalId()) {
240+
in visitedNodeReferenceKeys -> continue
241+
else -> visitedNodeReferenceKeys += key
242+
}
243+
238244
val children = parent.visitDependencies { children ->
239245
// Map to a list instead of to a sequence, so that the conversion to the stable reference is done
240246
// within this code block. After leaving the block, the node reference are not valid anymore.

0 commit comments

Comments
 (0)