Skip to content

Commit b06cb5b

Browse files
committed
Revert "Fix rare multi-packet string corruption (#3505) (#3513)"
This reverts commit 1af7327.
1 parent 997907c commit b06cb5b

File tree

4 files changed

+27
-214
lines changed

4 files changed

+27
-214
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13085,10 +13085,11 @@ internal TdsOperationStatus TryReadPlpUnicodeCharsWithContinue(TdsParserStateObj
1308513085

1308613086
if (canContinue)
1308713087
{
13088-
temp = stateObj.TryTakeSnapshotStorage() as char[];
13089-
Debug.Assert(temp != null || !isContinuing, "if continuing stored buffer must be present to contain previous data to continue from");
13090-
Debug.Assert(temp == null || length == int.MaxValue || temp.Length == length, "stored buffer length must be null or must have been created with the correct length");
13091-
13088+
if (isContinuing || isStarting)
13089+
{
13090+
temp = stateObj.TryTakeSnapshotStorage() as char[];
13091+
Debug.Assert(temp == null || length == int.MaxValue || temp.Length == length, "stored buffer length must be null or must have been created with the correct length");
13092+
}
1309213093
if (temp != null)
1309313094
{
1309413095
startOffset = stateObj.GetSnapshotTotalSize();
@@ -13104,7 +13105,7 @@ internal TdsOperationStatus TryReadPlpUnicodeCharsWithContinue(TdsParserStateObj
1310413105
supportRentedBuff: !canContinue, // do not use the arraypool if we are going to keep the buffer in the snapshot
1310513106
rentedBuff: ref buffIsRented,
1310613107
startOffset,
13107-
canContinue
13108+
isStarting || isContinuing
1310813109
);
1310913110

1311013111
if (result == TdsOperationStatus.Done)
@@ -13131,7 +13132,7 @@ internal TdsOperationStatus TryReadPlpUnicodeCharsWithContinue(TdsParserStateObj
1313113132
}
1313213133
else if (result == TdsOperationStatus.NeedMoreData)
1313313134
{
13134-
if (canContinue)
13135+
if (isStarting || isContinuing)
1313513136
{
1313613137
stateObj.SetSnapshotStorage(temp);
1313713138
}

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13266,10 +13266,11 @@ internal TdsOperationStatus TryReadPlpUnicodeCharsWithContinue(TdsParserStateObj
1326613266

1326713267
if (canContinue)
1326813268
{
13269-
temp = stateObj.TryTakeSnapshotStorage() as char[];
13270-
Debug.Assert(temp != null || !isContinuing, "if continuing stored buffer must be present to contain previous data to continue from");
13271-
Debug.Assert(temp == null || length == int.MaxValue || temp.Length == length, "stored buffer length must be null or must have been created with the correct length");
13272-
13269+
if (isContinuing || isStarting)
13270+
{
13271+
temp = stateObj.TryTakeSnapshotStorage() as char[];
13272+
Debug.Assert(temp == null || length == int.MaxValue || temp.Length == length, "stored buffer length must be null or must have been created with the correct length");
13273+
}
1327313274
if (temp != null)
1327413275
{
1327513276
startOffset = stateObj.GetSnapshotTotalSize();
@@ -13284,8 +13285,8 @@ internal TdsOperationStatus TryReadPlpUnicodeCharsWithContinue(TdsParserStateObj
1328413285
out length,
1328513286
supportRentedBuff: !canContinue, // do not use the arraypool if we are going to keep the buffer in the snapshot
1328613287
rentedBuff: ref buffIsRented,
13287-
startOffset,
13288-
canContinue
13288+
startOffset,
13289+
isStarting || isContinuing
1328913290
);
1329013291

1329113292
if (result == TdsOperationStatus.Done)
@@ -13312,7 +13313,7 @@ internal TdsOperationStatus TryReadPlpUnicodeCharsWithContinue(TdsParserStateObj
1331213313
}
1331313314
else if (result == TdsOperationStatus.NeedMoreData)
1331413315
{
13315-
if (canContinue)
13316+
if (isStarting || isContinuing)
1331613317
{
1331713318
stateObj.SetSnapshotStorage(temp);
1331813319
}

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,10 +1527,11 @@ public TdsOperationStatus TryReadByteArrayWithContinue(int length, out byte[] by
15271527
(bool canContinue, bool isStarting, bool isContinuing) = GetSnapshotStatuses();
15281528
if (canContinue)
15291529
{
1530-
temp = TryTakeSnapshotStorage() as byte[];
1531-
Debug.Assert(temp != null || !isContinuing, "if continuing stored buffer must be present to contain previous data to continue from");
1532-
Debug.Assert(bytes == null || bytes.Length == length, "stored buffer length must be null or must have been created with the correct length");
1533-
1530+
if (isContinuing || isStarting)
1531+
{
1532+
temp = TryTakeSnapshotStorage() as byte[];
1533+
Debug.Assert(bytes == null || bytes.Length == length, "stored buffer length must be null or must have been created with the correct length");
1534+
}
15341535
if (temp != null)
15351536
{
15361537
offset = GetSnapshotTotalSize();
@@ -1551,7 +1552,7 @@ public TdsOperationStatus TryReadByteArrayWithContinue(int length, out byte[] by
15511552
}
15521553
else if (result == TdsOperationStatus.NeedMoreData)
15531554
{
1554-
if (canContinue)
1555+
if (isStarting || isContinuing)
15551556
{
15561557
SetSnapshotStorage(temp);
15571558
}
@@ -1980,10 +1981,11 @@ internal TdsOperationStatus TryReadStringWithEncoding(int length, System.Text.En
19801981
int startOffset = 0;
19811982
if (canContinue)
19821983
{
1983-
buf = TryTakeSnapshotStorage() as byte[];
1984-
Debug.Assert(buf != null || !isContinuing, "if continuing stored buffer must be present to contain previous data to continue from");
1985-
Debug.Assert(buf == null || buf.Length == length, "stored buffer length must be null or must have been created with the correct length");
1986-
1984+
if (isContinuing || isStarting)
1985+
{
1986+
buf = TryTakeSnapshotStorage() as byte[];
1987+
Debug.Assert(buf == null || buf.Length == length, "stored buffer length must be null or must have been created with the correct length");
1988+
}
19871989
if (buf != null)
19881990
{
19891991
startOffset = GetSnapshotTotalSize();
@@ -2001,7 +2003,7 @@ internal TdsOperationStatus TryReadStringWithEncoding(int length, System.Text.En
20012003
{
20022004
if (result == TdsOperationStatus.NeedMoreData)
20032005
{
2004-
if (canContinue)
2006+
if (isStarting || isContinuing)
20052007
{
20062008
SetSnapshotStorage(buf);
20072009
}

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderTest.cs

Lines changed: 0 additions & 191 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)