From 593cc8f87cb54deddfd120e6c3bca3ce761a6ab7 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 3 Dec 2026 13:03:13 -0800 Subject: [PATCH] fix(csi): refuse a replicationFactor beyond int32 (#1011) Merge note (batch b5; pull_request_target spec-trace workflow has a startup_failure, so its checks run locally): - One Test run (47198949595) succeeded (go test (linux), process-level tests (real binaries)) on the integration tree 22da3420 = main 5bf18d62 + #1011 #1012 in this order; these squash merges reproduce that tree, verified after the last one. - spec-trace-check.sh and public-text-check.sh, run with main's scripts against this head and body: both exit 0. - Code review ACCEPT on 80f3b84a: a replicationFactor beyond int32 is refused as InvalidArgument before any conversion or provisioner call; MaxInt32 passes unchanged, MaxInt32+1 and larger make zero calls. --- seaweed-block/core/csi/controller.go | 4 +-- seaweed-block/core/csi/controller_test.go | 30 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) 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) + } +}