Skip to content

Commit

Permalink
Fix some issues found by fuzzer
Browse files Browse the repository at this point in the history
- Catch json parse exception in rekor response
- Check bundle before reading first tlog entry

Signed-off-by: Appu Goundan <appu@google.com>
  • Loading branch information
loosebazooka committed Aug 3, 2023
1 parent 0d557a2 commit 781b03b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ static KeylessSignature readBundle(Reader jsonReader) throws BundleParseExceptio
}
Bundle bundle = bundleBuilder.build();

if (bundle.getVerificationMaterial().getTlogEntriesCount() == 0) {
throw new BundleParseException("Could not find an tlog entries in bundle json");
}
var bundleEntry = bundle.getVerificationMaterial().getTlogEntries(0);
var bundleInclusionProof = bundleEntry.getInclusionProof();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ public class RekorParseException extends Exception {
public RekorParseException(String message) {
super(message);
}

public RekorParseException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static dev.sigstore.json.GsonSupplier.GSON;

import com.google.common.reflect.TypeToken;
import com.google.gson.JsonSyntaxException;
import java.net.URI;
import java.util.Map;
import org.immutables.value.Value;
Expand Down Expand Up @@ -56,7 +57,12 @@ public interface RekorResponse {
static RekorResponse newRekorResponse(URI entryLocation, String rawResponse)
throws RekorParseException {
var type = new TypeToken<Map<String, RekorEntry>>() {}.getType();
Map<String, RekorEntry> entryMap = GSON.get().fromJson(rawResponse, type);
Map<String, RekorEntry> entryMap;
try {
entryMap = GSON.get().fromJson(rawResponse, type);
} catch (JsonSyntaxException jse) {
throw new RekorParseException("Rekor entry json could not be parsed", jse);
}
if (entryMap == null) {
throw new RekorParseException("Expecting a single rekor entry in response but found none");
}
Expand Down

0 comments on commit 781b03b

Please sign in to comment.