From 83231752f73524f40d1b4e14d54f542e8a9b6125 Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Sat, 12 Aug 2023 11:10:53 +0100 Subject: [PATCH] make array rental return after TryReadPlpUnicodeChars unconditional --- .../src/Microsoft/Data/SqlClient/TdsParser.cs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs index 8c16690149..899ea5fa7f 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs @@ -5683,18 +5683,20 @@ private bool TryReadSqlStringValue(SqlBuffer value, byte type, int length, Encod { char[] cc = null; bool buffIsRented = false; - if (!TryReadPlpUnicodeChars(ref cc, 0, length >> 1, stateObj, out length, supportRentedBuff: true, rentedBuff: ref buffIsRented)) - { - return false; - } - if (length > 0) - { - s = new string(cc, 0, length); - } - else + bool result = TryReadPlpUnicodeChars(ref cc, 0, length >> 1, stateObj, out length, supportRentedBuff: true, rentedBuff: ref buffIsRented); + + if (result) { - s = ""; + if (length > 0) + { + s = new string(cc, 0, length); + } + else + { + s = ""; + } } + if (buffIsRented) { // do not use clearArray:true on the rented array because it can be massively larger @@ -5705,6 +5707,11 @@ private bool TryReadSqlStringValue(SqlBuffer value, byte type, int length, Encod ArrayPool.Shared.Return(cc, clearArray: false); cc = null; } + + if (!result) + { + return false; + } } else {