diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlUtil.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlUtil.cs index 2c43a9b253..ec1137888f 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlUtil.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlUtil.cs @@ -817,6 +817,12 @@ static internal Exception UDTInvalidSqlType(string typeName) { return ADP.Argument(StringsHelper.GetString(Strings.SQLUDT_InvalidSqlType, typeName)); } + + static internal Exception UDTInvalidSize(int maxSize, int maxSupportedSize) + { + throw ADP.ArgumentOutOfRange(StringsHelper.GetString(Strings.SQLUDT_InvalidSize, maxSize, maxSupportedSize)); + } + static internal Exception InvalidSqlDbTypeForConstructor(SqlDbType type) { diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs index 54e707380b..ed46f723df 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs @@ -9965,10 +9965,12 @@ internal Task TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, int timeout, boo Debug.Assert(_isYukon, "Invalid DataType UDT for non-Yukon or later server!"); + int maxSupportedSize = IsKatmaiOrNewer ? int.MaxValue : short.MaxValue; + if (!isNull) { // When writing UDT parameter values to the TDS stream, allow sending byte[] or SqlBytes - // directly to the server and not rejected as invalid. This allows users to handle + // directly to the server and not reject them as invalid. This allows users to handle // serialization and deserialization logic without having to have SqlClient be aware of // the types and without using inefficient text representations. if (value is byte[] rawBytes) @@ -9999,19 +10001,15 @@ internal Task TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, int timeout, boo size = udtVal.Length; //it may be legitimate, but we dont support it yet - if (size < 0 || (size >= UInt16.MaxValue && maxsize != -1)) - throw new IndexOutOfRangeException(); + if (size < 0 || (size >= maxSupportedSize && maxsize != -1)) + { + throw SQL.UDTInvalidSize(maxsize, maxSupportedSize); + } } - //if this is NULL value, write special null value - byte[] lenBytes = BitConverter.GetBytes((Int64)size); - - if (ADP.IsEmpty(param.UdtTypeName)) - throw SQL.MustSetUdtTypeNameForUdtParams(); - // Split the input name. TypeName is returned as single 3 part name during DeriveParameters. // NOTE: ParseUdtTypeName throws if format is incorrect - String[] names = SqlParameter.ParseTypeName(param.UdtTypeName, true /* is UdtTypeName */); + String[] names = SqlParameter.ParseTypeName(param.UdtTypeName, isUdtTypeName: true); if (!ADP.IsEmpty(names[0]) && TdsEnums.MAX_SERVERNAME < names[0].Length) { throw ADP.ArgumentOutOfRange("names"); diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Resources/Strings.Designer.cs b/src/Microsoft.Data.SqlClient/netfx/src/Resources/Strings.Designer.cs index 0e7cf7910a..6278d24d22 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Resources/Strings.Designer.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Resources/Strings.Designer.cs @@ -11403,6 +11403,15 @@ internal static string SQLUDT_InvalidDbId { } } + /// + /// Looks up a localized string similar to UDT size must be less than {1}, size: {0}. + /// + internal static string SQLUDT_InvalidSize { + get { + return ResourceManager.GetString("SQLUDT_InvalidSize", resourceCulture); + } + } + /// /// Looks up a localized string similar to Specified type is not registered on the target server.{0}.. /// diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Resources/Strings.resx b/src/Microsoft.Data.SqlClient/netfx/src/Resources/Strings.resx index 20193d1e49..b9879723ae 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Resources/Strings.resx +++ b/src/Microsoft.Data.SqlClient/netfx/src/Resources/Strings.resx @@ -4527,4 +4527,7 @@ Error occurred when generating enclave package. Attestation Protocol has not been specified in the connection string, but the query requires enclave computations. - + + UDT size must be less than {1}, size: {0} + + \ No newline at end of file