diff --git a/seaweed-block/core/csi/controller.go b/seaweed-block/core/csi/controller.go index 215ce9b18c..dd2f5e8554 100644 --- a/seaweed-block/core/csi/controller.go +++ b/seaweed-block/core/csi/controller.go @@ -280,11 +280,11 @@ func volumeSpecFromCreateRequest(req *csipb.CreateVolumeRequest) (VolumeSpec, er } rf := 1 if raw := req.GetParameters()["replicationFactor"]; raw != "" { - v, err := strconv.Atoi(raw) + v, err := strconv.ParseInt(raw, 10, 32) if err != nil || v <= 0 { return VolumeSpec{}, status.Errorf(codes.InvalidArgument, "invalid replicationFactor %q", raw) } - rf = v + rf = int(v) } protocol, err := protocolFromParameters(req.GetParameters()) if err != nil { diff --git a/seaweed-block/core/csi/controller_test.go b/seaweed-block/core/csi/controller_test.go index b7720b3d0f..a6c479c3ee 100644 --- a/seaweed-block/core/csi/controller_test.go +++ b/seaweed-block/core/csi/controller_test.go @@ -761,3 +761,33 @@ func authorityContextGuard(ctx map[string]string) error { } return nil } + +func TestControllerCreateVolume_RefusesReplicationFactorBeyondInt32(t *testing.T) { + create := func(raw string) (*stubProvisioner, error) { + prov := &stubProvisioner{} + s := NewControllerServerWithProvisioner(&stubLookup{}, prov) + _, err := s.CreateVolume(context.Background(), &csipb.CreateVolumeRequest{ + Name: "pvc-a", + CapacityRange: &csipb.CapacityRange{RequiredBytes: 1 << 30}, + Parameters: map[string]string{"replicationFactor": raw}, + VolumeCapabilities: []*csipb.VolumeCapability{testVolumeCapability()}, + }) + return prov, err + } + for _, raw := range []string{"4294967298", "2147483648"} { + prov, err := create(raw) + if status.Code(err) != codes.InvalidArgument { + t.Fatalf("replicationFactor=%s: err=%v want InvalidArgument", raw, err) + } + if len(prov.calls) != 0 { + t.Fatalf("replicationFactor=%s: provisioner calls=%d want 0", raw, len(prov.calls)) + } + } + prov, err := create("2147483647") + if err != nil { + t.Fatalf("replicationFactor=2147483647: %v", err) + } + if len(prov.calls) != 1 || prov.calls[0].ReplicationFactor != 2147483647 { + t.Fatalf("replicationFactor=2147483647: calls=%+v", prov.calls) + } +}