Skip to content

Commit 59dae85

Browse files
authored
Merge pull request #473 from sigstore/fix-a-fuzzing-issue
Fix fuzzing issues
2 parents 0d557a2 + 53dd398 commit 59dae85

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

sigstore-java/src/main/java/dev/sigstore/bundle/BundleFactoryInternal.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ static KeylessSignature readBundle(Reader jsonReader) throws BundleParseExceptio
158158
}
159159
Bundle bundle = bundleBuilder.build();
160160

161+
if (bundle.getVerificationMaterial().getTlogEntriesCount() == 0) {
162+
throw new BundleParseException("Could not find any tlog entries in bundle json");
163+
}
161164
var bundleEntry = bundle.getVerificationMaterial().getTlogEntries(0);
162165
var bundleInclusionProof = bundleEntry.getInclusionProof();
163166

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ public class RekorParseException extends Exception {
1919
public RekorParseException(String message) {
2020
super(message);
2121
}
22+
23+
public RekorParseException(String message, Throwable cause) {
24+
super(message, cause);
25+
}
2226
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static dev.sigstore.json.GsonSupplier.GSON;
1919

2020
import com.google.common.reflect.TypeToken;
21+
import com.google.gson.JsonSyntaxException;
2122
import java.net.URI;
2223
import java.util.Map;
2324
import org.immutables.value.Value;
@@ -53,10 +54,15 @@ public interface RekorResponse {
5354
* @return an immutable {@link RekorResponse} instance
5455
* @throws RekorParseException if the rawResponse doesn't parse directly to a single rekor entry
5556
*/
56-
static RekorResponse newRekorResponse(URI entryLocation, String rawResponse)
57+
public static RekorResponse newRekorResponse(URI entryLocation, String rawResponse)
5758
throws RekorParseException {
5859
var type = new TypeToken<Map<String, RekorEntry>>() {}.getType();
59-
Map<String, RekorEntry> entryMap = GSON.get().fromJson(rawResponse, type);
60+
Map<String, RekorEntry> entryMap;
61+
try {
62+
entryMap = GSON.get().fromJson(rawResponse, type);
63+
} catch (JsonSyntaxException | NullPointerException | StringIndexOutOfBoundsException ex) {
64+
throw new RekorParseException("Rekor entry json could not be parsed: " + rawResponse, ex);
65+
}
6066
if (entryMap == null) {
6167
throw new RekorParseException("Expecting a single rekor entry in response but found none");
6268
}

0 commit comments

Comments
 (0)