Skip to content

Commit b2f4c75

Browse files
committed
additinal fix for 0 length case
1 parent 1b95627 commit b2f4c75

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,7 +1966,8 @@ internal TdsOperationStatus TryReadStringWithEncoding(int length, System.Text.En
19661966

19671967
if (isPlp)
19681968
{
1969-
TdsOperationStatus result = TryReadPlpBytes(ref buf, 0, int.MaxValue, out length);
1969+
bool compatibilityMode = LocalAppContextSwitches.UseCompatibilityAsyncBehaviour;
1970+
TdsOperationStatus result = TryReadPlpBytes(ref buf, 0, int.MaxValue, out length, canContinue && !compatibilityMode, canContinue && !compatibilityMode, compatibilityMode);
19701971
if (result != TdsOperationStatus.Done)
19711972
{
19721973
value = null;
@@ -2128,12 +2129,10 @@ internal int ReadPlpBytesChunk(byte[] buff, int offset, int len)
21282129
internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len, out int totalBytesRead)
21292130
{
21302131
bool canContinue = false;
2131-
bool isStarting = false;
2132-
bool isContinuing = false;
21332132
bool compatibilityMode = LocalAppContextSwitches.UseCompatibilityAsyncBehaviour;
21342133
if (!compatibilityMode)
21352134
{
2136-
(canContinue, isStarting, isContinuing) = GetSnapshotStatuses();
2135+
(canContinue, _, _) = GetSnapshotStatuses();
21372136
}
21382137
return TryReadPlpBytes(ref buff, offset, len, out totalBytesRead, canContinue, canContinue, compatibilityMode);
21392138
}
@@ -2157,7 +2156,16 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
21572156
}
21582157

21592158
AssertValidState();
2160-
totalBytesRead = 0;
2159+
if (writeDataSizeToSnapshot && canContinue && _snapshot != null)
2160+
{
2161+
// if there is a snapshot which it contains a stored plp buffer take it
2162+
// and try to use it if it is the right length
2163+
buff = TryTakeSnapshotStorage() as byte[];
2164+
if (buff != null)
2165+
{
2166+
totalBytesRead = _snapshot.GetPacketDataOffset();
2167+
}
2168+
}
21612169
return TdsOperationStatus.Done; // No data
21622170
}
21632171

0 commit comments

Comments
 (0)