Skip to content

Commit 8e5c680

Browse files
authored
Merge pull request #474 from sigstore/more-fuzzing
Handle more uncaught runtime exceptions on rekor response
2 parents 59dae85 + 72af1f8 commit 8e5c680

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

sigstore-java/src/main/java/dev/sigstore/rekor/client/RekorResponse.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@ public interface RekorResponse {
5454
* @return an immutable {@link RekorResponse} instance
5555
* @throws RekorParseException if the rawResponse doesn't parse directly to a single rekor entry
5656
*/
57-
public static RekorResponse newRekorResponse(URI entryLocation, String rawResponse)
57+
static RekorResponse newRekorResponse(URI entryLocation, String rawResponse)
5858
throws RekorParseException {
5959
var type = new TypeToken<Map<String, RekorEntry>>() {}.getType();
6060
Map<String, RekorEntry> entryMap;
6161
try {
6262
entryMap = GSON.get().fromJson(rawResponse, type);
63-
} catch (JsonSyntaxException | NullPointerException | StringIndexOutOfBoundsException ex) {
63+
} catch (JsonSyntaxException
64+
| NullPointerException
65+
| NumberFormatException
66+
| StringIndexOutOfBoundsException ex) {
6467
throw new RekorParseException("Rekor entry json could not be parsed: " + rawResponse, ex);
6568
}
6669
if (entryMap == null) {
@@ -71,6 +74,10 @@ public static RekorResponse newRekorResponse(URI entryLocation, String rawRespon
7174
"Expecting a single rekor entry in response but found: " + entryMap.size());
7275
}
7376
var entry = entryMap.entrySet().iterator().next();
77+
if (entry == null || entry.getKey() == null || entry.getValue() == null) {
78+
throw new RekorParseException(
79+
"Expecting single rekor entry but found an invalid entry: " + rawResponse);
80+
}
7481
return ImmutableRekorResponse.builder()
7582
.entryLocation(entryLocation)
7683
.raw(rawResponse)

0 commit comments

Comments
 (0)