Skip to content

fix: Prevent JSONException when SARIF invocations array is empty - #353

Merged
davewichers merged 2 commits into
OWASP-Benchmark:mainfrom
TheLivan:fix/sarif-empty-invocations
Oct 14, 2026
Merged

davewichers merged 2 commits into
OWASP-Benchmark:mainfrom
TheLivan:fix/sarif-empty-invocations

Conversation

@TheLivan

Copy link
Copy Markdown
Contributor

Problem

SarifReader.hasInvocationTimes() checked that invocations exists but not that it has any elements. Some tools (e.g. PVS-Studio) emit "invocations": [], so firstInvocation() threw a JSONException and parsing of the whole report failed.

Fix

hasInvocationTimes() now returns false when the invocations array is empty, so the reader uses the same fallback as when invocations is missing: the scan time is taken from the result file name if it ends with -<seconds>, otherwise it is reported as "Time not specified". Findings are parsed normally in both cases.

This affects all SARIF-based readers.

Tests

  • Added SarifReaderTest#fallsBackToFilenameTimeWhenInvocationsArrayIsEmpty: it parses a SARIF report with an empty invocations array and checks that the time comes from the file name.

@TheLivan TheLivan changed the title Fix/sarif empty invocations fix: Prevent JSONException when SARIF invocations array is empty Oct 12, 2026

@darkspirit510 darkspirit510 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I wonder how you actually found this one? Just one minor code style question. Else it is fine.

&& firstInvocation(resultFile).has("startTimeUtc")
&& firstInvocation(resultFile).has("endTimeUtc");
JSONObject firstRun = firstRun(resultFile);
if (firstRun.has("invocations") && !firstRun.getJSONArray("invocations").isEmpty()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about either using guard statements

private static boolean hasInvocationTimes(ResultFile resultFile) {
    JSONObject firstRun = firstRun(resultFile);
    if (!firstRun.has("invocations")) {
        return false;
    }

    JSONArray invocations = firstRun.getJSONArray("invocations");
    if (invocations.isEmpty()) {
        return false;
    }

    JSONObject firstInvocation = invocations.getJSONObject(0);
    return firstInvocation.has("startTimeUtc") && firstInvocation.has("endTimeUtc");
}

or implicit return value

private static boolean hasInvocationTimes(ResultFile resultFile) {
        JSONObject firstRun = firstRun(resultFile);
        return firstRun.has("invocations")
            && !firstRun.getJSONArray("invocations").isEmpty()
            && firstRun.getJSONArray("invocations").getJSONObject(0).has("startTimeUtc")
            && firstRun.getJSONArray("invocations").getJSONObject(0).has("endTimeUtc");

    }

instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, went with the first option. Tests are green.

@TheLivan
TheLivan force-pushed the fix/sarif-empty-invocations branch from e0a49c8 to ee44e89 Compare October 12, 2026 14:30
@TheLivan

Copy link
Copy Markdown
Contributor Author

Thanks! I'm currently working on adding support for your benchmark to PVS-Studio. We convert our reports from JSON to SARIF with a separate utility, and that utility has no idea how long the analysis took, so it leaves the invocations array empty. That's how I ran into this.

Really cool benchmark, by the way :)

If this PR gets merged, I'll open another one with a reader for the PVS-Studio analyzer itself.

@darkspirit510 darkspirit510 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davewichers can be merged.

@davewichers
davewichers merged commit 5a50752 into OWASP-Benchmark:main Oct 14, 2026
1 check passed
@TheLivan
TheLivan deleted the fix/sarif-empty-invocations branch October 14, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants