Skip to content

Commit 4af5c0a

Browse files
Reject empty vector payloads in VADD and VSIM
Add a common values.IsEmpty check after all type-specific branches in both VADD and VSIM to reject zero-dimension vector requests with a clear error instead of passing them through to DiskANN. The FP32 alignment check remains in the FP32-specific branch. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c37e381 commit 4af5c0a

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

libs/server/Resp/Vector/RespServerSessionVectors.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ private bool NetworkVADD<TGarnetApi>(ref TGarnetApi storageApi)
142142
values = asBytes;
143143
}
144144

145+
if (values.IsEmpty)
146+
{
147+
return AbortWithErrorMessage("ERR vector values must be non-empty");
148+
}
149+
145150
if (curIx >= parseState.Count)
146151
{
147152
return AbortWithWrongNumberOfArguments("VADD");
@@ -587,6 +592,11 @@ private bool NetworkVSIM<TGarnetApi>(ref TGarnetApi storageApi)
587592
}
588593
}
589594

595+
if (!element.HasValue && values.IsEmpty)
596+
{
597+
return AbortWithErrorMessage("ERR vector values must be non-empty");
598+
}
599+
590600
bool? withScores = null;
591601
bool? withAttributes = null;
592602
int? count = null;

test/Garnet.test/RespVectorSetTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,14 @@ public void VADDErrors()
405405
var exc15 = ClassicAssert.Throws<RedisServerException>(() => db.Execute("VADD", [vectorSetKey, "FP32", blob, "bar"]));
406406
ClassicAssert.AreEqual("ERR invalid vector specification", exc15.Message);
407407

408+
// Empty vector payloads should be rejected for all binary types
409+
var excEmptyFP32 = ClassicAssert.Throws<RedisServerException>(() => db.Execute("VADD", [vectorSetKey, "FP32", Array.Empty<byte>(), "bar"]));
410+
ClassicAssert.AreEqual("ERR vector values must be non-empty", excEmptyFP32.Message);
411+
var excEmptyXB8 = ClassicAssert.Throws<RedisServerException>(() => db.Execute("VADD", [vectorSetKey, "XB8", Array.Empty<byte>(), "bar"]));
412+
ClassicAssert.AreEqual("ERR vector values must be non-empty", excEmptyXB8.Message);
413+
var excEmptySB8 = ClassicAssert.Throws<RedisServerException>(() => db.Execute("VADD", [vectorSetKey, "SB8", Array.Empty<byte>(), "bar"]));
414+
ClassicAssert.AreEqual("ERR vector values must be non-empty", excEmptySB8.Message);
415+
408416
// Mismatch after creating a vector set
409417
_ = db.KeyDelete(vectorSetKey);
410418

0 commit comments

Comments
 (0)