mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
seaweed-block: refuse a CSI replicationFactor beyond int32
Same change as the module's upstream commit b9ee7f1c (#1011), applied under seaweed-block/: an oversized StorageClass replicationFactor is refused as InvalidArgument instead of wrapping on conversion. Ships in seaweed-block v1.1.1; a later sync carries the identical change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
87d52c6840
commit
b20fcb92b0
2 files changed
+32
-2
No files matched your search
@@ -260,11 +260,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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user