Fraunhofer-AISEC / cpg

A library to extract Code Property Graphs from C/C++, Java, Go, Python, Ruby and every other language through LLVM-IR.
https://fraunhofer-aisec.github.io/cpg/
Apache License 2.0
281 stars 62 forks source link

ArrayIndexOutOfBoundsException when printing benchmark results #876

Closed seelchen closed 2 years ago

seelchen commented 2 years ago

When using the StatisticsCollectionPass and printing the benchmark results, an ArrayIndexOutOfBoundsException is thrown. I think this happenes because the MeasurementHolder from the StatisticsCollectionPass holds two measurements unlike the other Benchmarks which only hold one measurement. When they are converted into the table for printing, the MeasurementHolder is converted into a list with length 4 which doesn't align with the other lists with length 2.

Stack trace

Exception in thread "main" java.util.concurrent.ExecutionException: java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
    at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
    at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2022)
    at de.fraunhofer.aisec.codyze.specification_languages.mark.MarkExecutor.evaluate(MarkExecutor.kt:105)
    at de.fraunhofer.aisec.codyze_core.Project.doStuff(Project.kt:35)
    at de.fraunhofer.aisec.codyze.Analyze.run(SubcommandAnalyze.kt:37)
    at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:198)
    at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:211)
    at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:18)
    at com.github.ajalt.clikt.core.CliktCommand.parse(CliktCommand.kt:400)
    at com.github.ajalt.clikt.core.CliktCommand.parse$default(CliktCommand.kt:397)
    at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:415)
    at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:440)
    at de.fraunhofer.aisec.codyze.MainKt.main(Main.kt:85)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
    at de.fraunhofer.aisec.cpg.helpers.MeasurementHolderKt.printMarkdown(MeasurementHolder.kt:90)
    at de.fraunhofer.aisec.cpg.helpers.BenchmarkResults.print(MeasurementHolder.kt:51)
    at de.fraunhofer.aisec.codyze.specification_languages.mark.MarkExecutor.evaluate$lambda-1(MarkExecutor.kt:64)
    at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
    at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
    at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1705)
    at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1692)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

Code of interest

        analyzer.analyze()
            .thenApply {
                it.benchmarkResults.print()
                it
            }

Changes to the configuration

                TranslationConfiguration.builder()
                    .defaultLanguages()
                    .sourceLocations(source.map { (it.toFile()) })
                    .defaultPasses()
                    .registerPass(StatisticsCollectionPass())
oxisto commented 2 years ago

Do you have an example code that triggers this?

seelchen commented 2 years ago

It was triggered with a file from the test resources of Codyze.