From 4dd68645cb36e04aa5601d92e9a6333dd8e06453 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 18 Mar 2026 11:32:39 -0700 Subject: [PATCH] fix VolumeEcShardsToVolume to validate dataShards range Go validates that dataShards is > 0 and <= MaxShardCount before proceeding with EC-to-volume reconstruction. Without this check, a zero or excessively large data_shards value could cause confusing downstream failures. --- seaweed-volume/src/server/grpc_server.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/seaweed-volume/src/server/grpc_server.rs b/seaweed-volume/src/server/grpc_server.rs index 2b938a3a6..06a5a5832 100644 --- a/seaweed-volume/src/server/grpc_server.rs +++ b/seaweed-volume/src/server/grpc_server.rs @@ -2587,6 +2587,15 @@ impl VolumeServer for VolumeGrpcService { // Use EC context data shard count from the volume let data_shards = ec_vol.data_shards as usize; + // Validate data shard count range (matches Go's VolumeEcShardsToVolume) + let max_shard_count = crate::storage::erasure_coding::ec_shard::MAX_SHARD_COUNT; + if data_shards == 0 || data_shards > max_shard_count { + return Err(Status::invalid_argument(format!( + "invalid data shard count {} for volume {} (must be 1..{})", + data_shards, req.volume_id, max_shard_count + ))); + } + // Check that all data shards are present for shard_id in 0..data_shards { if ec_vol