fix(gateway): reject oversized sparse array total_length with InvalidArgument
Guard against proto uint32 total_length values that exceed Array.MaxLength before casting; the previous checked cast threw OverflowException (gRPC Internal) instead of the intended InvalidArgument. Adds tests for the new guard, for the null-value ArgumentNullException path, and removes the checked keyword (redundant after the guard).
This commit is contained in:
@@ -62,7 +62,13 @@ internal static class SparseArrayExpander
|
||||
throw Invalid($"Sparse array element_data_type '{elementType}' is not a supported scalar element type.");
|
||||
}
|
||||
|
||||
int length = checked((int)totalLength);
|
||||
if (totalLength > (uint)Array.MaxLength)
|
||||
{
|
||||
throw Invalid(
|
||||
$"Sparse array total_length {totalLength} exceeds the maximum supported array length {Array.MaxLength}.");
|
||||
}
|
||||
|
||||
int length = (int)totalLength;
|
||||
HashSet<uint> seenIndices = new();
|
||||
|
||||
foreach (MxSparseElement element in sparse.Elements)
|
||||
|
||||
Reference in New Issue
Block a user