Skip to content

Commit 72fcff9

Browse files
committed
SpliceBlob: check that the digest function is supported
1 parent 11d575b commit 72fcff9

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

server/grpc_cas.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,19 @@ func (s *grpcServer) SpliceBlob(ctx context.Context, req *pb.SpliceBlobRequest)
385385
"SpliceBlob called with nil SpliceBlobRequest")
386386
}
387387

388+
if req.DigestFunction != pb.DigestFunction_UNKNOWN && req.DigestFunction != pb.DigestFunction_SHA256 {
389+
digestName, ok := pb.DigestFunction_Value_name[int32(req.DigestFunction)]
390+
if ok {
391+
return nil, grpc_status.Errorf(codes.InvalidArgument,
392+
"SpliceBlob called with unsupported digest function: %s", digestName)
393+
}
394+
395+
return nil, grpc_status.Errorf(codes.InvalidArgument,
396+
"SpliceBlob called with unrecognised digest function: %d", req.DigestFunction)
397+
}
398+
399+
// From this point, we assume that the digest function is SHA256 and verify digests as necessary.
400+
388401
// Check that req.ChunkDigests is OK.
389402

390403
if len(req.ChunkDigests) == 0 {

server/grpc_cas_spliceblobs_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,3 +419,26 @@ func TestSpliceBlobWithMissingChunk(t *testing.T) {
419419
t.Fatal("expected \"missing\" blob not to exist in the cache yet, but got error", err)
420420
}
421421
}
422+
423+
func TestUnsupportedSpliceBlobDigestsAreRejected(t *testing.T) {
424+
fixture, helloDigest, worldDigest, helloworldDigest := spliceBlobTestSetup(t)
425+
defer func() { _ = os.Remove(fixture.tempdir) }()
426+
427+
spliceReq := pb.SpliceBlobRequest{
428+
BlobDigest: helloworldDigest,
429+
ChunkDigests: []*pb.Digest{
430+
helloDigest,
431+
worldDigest,
432+
},
433+
DigestFunction: pb.DigestFunction_MD5, // Unsupported
434+
}
435+
436+
_, err := fixture.casClient.SpliceBlob(ctx, &spliceReq)
437+
if err == nil {
438+
t.Fatal("expected error when specifying an unsupported SpliceBlobRequest.DigestFunction")
439+
}
440+
441+
if status.Code(err) != codes.InvalidArgument {
442+
t.Fatal("expected an InvalidArgument error, got:", err)
443+
}
444+
}

0 commit comments

Comments
 (0)