Skip to content

Commit 8c30101

Browse files
committed
Revert "Fix TryReadPlpBytes throws ArgumentException (#3470) (#3474)"
This reverts commit 0a55896.
1 parent b06cb5b commit 8c30101

File tree

3 files changed

+22
-47
lines changed

3 files changed

+22
-47
lines changed

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13359,13 +13359,6 @@ bool writeDataSizeToSnapshot
1335913359
break;
1336013360
}
1336113361
}
13362-
13363-
if (writeDataSizeToSnapshot)
13364-
{
13365-
stateObj.SetSnapshotStorage(null);
13366-
stateObj.ClearSnapshotDataSize();
13367-
}
13368-
1336913362
return TdsOperationStatus.Done;
1337013363

1337113364
static int IncrementSnapshotDataSize(TdsParserStateObject stateObj, bool resetting, int previousPacketId, int value)
@@ -13385,15 +13378,15 @@ static int IncrementSnapshotDataSize(TdsParserStateObject stateObj, bool resetti
1338513378
current = 0;
1338613379
}
1338713380

13388-
stateObj.AddSnapshotDataSize(current + value);
13381+
stateObj.SetSnapshotDataSize(current + value);
1338913382

1339013383
// return new packetid so next time we see this packet we know it isn't new
1339113384
return currentPacketId;
1339213385
}
1339313386
else
1339413387
{
1339513388
current = stateObj.GetSnapshotDataSize();
13396-
stateObj.AddSnapshotDataSize(current + value);
13389+
stateObj.SetSnapshotDataSize(current + value);
1339713390
return previousPacketId;
1339813391
}
1339913392
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13541,13 +13541,6 @@ bool writeDataSizeToSnapshot
1354113541
break;
1354213542
}
1354313543
}
13544-
13545-
if (writeDataSizeToSnapshot)
13546-
{
13547-
stateObj.SetSnapshotStorage(null);
13548-
stateObj.ClearSnapshotDataSize();
13549-
}
13550-
1355113544
return TdsOperationStatus.Done;
1355213545

1355313546
static int IncrementSnapshotDataSize(TdsParserStateObject stateObj, bool resetting, int previousPacketId, int value)
@@ -13567,15 +13560,15 @@ static int IncrementSnapshotDataSize(TdsParserStateObject stateObj, bool resetti
1356713560
current = 0;
1356813561
}
1356913562

13570-
stateObj.AddSnapshotDataSize(current + value);
13563+
stateObj.SetSnapshotDataSize(current + value);
1357113564

1357213565
// return new packetid so next time we see this packet we know it isn't new
1357313566
return currentPacketId;
1357413567
}
1357513568
else
1357613569
{
1357713570
current = stateObj.GetSnapshotDataSize();
13578-
stateObj.AddSnapshotDataSize(current + value);
13571+
stateObj.SetSnapshotDataSize(current + value);
1357913572
return previousPacketId;
1358013573
}
1358113574
}

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

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ public TdsOperationStatus TryReadByteArray(Span<byte> buff, int len, out int tot
15101510

15111511
if (writeDataSizeToSnapshot)
15121512
{
1513-
AddSnapshotDataSize(bytesToRead);
1513+
SetSnapshotDataSize(bytesToRead);
15141514
}
15151515

15161516
AssertValidState();
@@ -2056,7 +2056,7 @@ internal TdsOperationStatus TryReadPlpLength(bool returnPlpNullIfNull, out ulong
20562056
// bool firstchunk = false;
20572057
bool isNull = false;
20582058

2059-
Debug.Assert(_longlenleft == 0, "Out of sync length read request");
2059+
Debug.Assert(_longlenleft == 0, "Out of synch length read request");
20602060
if (_longlen == 0)
20612061
{
20622062
// First chunk is being read. Find out what type of chunk it is
@@ -2137,7 +2137,6 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
21372137
}
21382138
return TryReadPlpBytes(ref buff, offset, len, out totalBytesRead, canContinue, canContinue, compatibilityMode);
21392139
}
2140-
21412140
// Reads the requested number of bytes from a plp data stream, or the entire data if
21422141
// requested length is -1 or larger than the actual length of data. First call to this method
21432142
// should be preceeded by a call to ReadPlpLength or ReadDataLength.
@@ -2253,14 +2252,14 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
22532252
SetSnapshotStorage(buff);
22542253
if (writeDataSizeToSnapshot)
22552254
{
2256-
AddSnapshotDataSize(bytesRead);
2255+
SetSnapshotDataSize(bytesRead);
22572256
}
22582257
}
22592258
return result;
22602259
}
22612260
if (writeDataSizeToSnapshot && canContinue)
22622261
{
2263-
AddSnapshotDataSize(bytesRead);
2262+
SetSnapshotDataSize(bytesRead);
22642263
}
22652264

22662265
if (_longlenleft == 0)
@@ -2278,7 +2277,10 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
22782277
else if (canContinue && result == TdsOperationStatus.NeedMoreData)
22792278
{
22802279
SetSnapshotStorage(buff);
2281-
// data bytes read from the current packet must be 0 here so do not save the snapshot data size
2280+
if (writeDataSizeToSnapshot)
2281+
{
2282+
SetSnapshotDataSize(bytesRead);
2283+
}
22822284
}
22832285
return result;
22842286
}
@@ -2292,12 +2294,6 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
22922294
break;
22932295
}
22942296
}
2295-
2296-
if (canContinue)
2297-
{
2298-
SetSnapshotStorage(null);
2299-
ClearSnapshotDataSize();
2300-
}
23012297
return TdsOperationStatus.Done;
23022298
}
23032299

@@ -3533,6 +3529,9 @@ internal void ResetSnapshot()
35333529
{
35343530
StateSnapshot snapshot = _snapshot;
35353531
_snapshot = null;
3532+
// TODO(GH-3385): Not sure what this is trying to assert, but it
3533+
// currently fails the DataReader tests.
3534+
// Debug.Assert(snapshot._storage == null);
35363535
snapshot.Clear();
35373536
Interlocked.CompareExchange(ref _cachedSnapshot, snapshot, null);
35383537
}
@@ -3590,6 +3589,9 @@ internal object TryTakeSnapshotStorage()
35903589
internal void SetSnapshotStorage(object buffer)
35913590
{
35923591
Debug.Assert(_snapshot != null, "should not access snapshot accessor functions without first checking that the snapshot is available");
3592+
// TODO(GH-3385): Not sure what this is trying to assert, but it
3593+
// currently fails the DataReader tests.
3594+
// Debug.Assert(_snapshot._storage == null, "should not overwrite snapshot stored buffer");
35933595
if (_snapshot != null)
35943596
{
35953597
_snapshot._storage = buffer;
@@ -3601,18 +3603,12 @@ internal void SetSnapshotStorage(object buffer)
36013603
/// countOfBytesCopiedFromCurrentPacket to be calculated
36023604
/// </summary>
36033605
/// <param name="countOfBytesCopiedFromCurrentPacket"></param>
3604-
internal void AddSnapshotDataSize(int countOfBytesCopiedFromCurrentPacket)
3606+
internal void SetSnapshotDataSize(int countOfBytesCopiedFromCurrentPacket)
36053607
{
36063608
Debug.Assert(_snapshot != null && _snapshot.ContinueEnabled, "_snapshot must exist to store packet data size");
36073609
_snapshot.SetPacketDataSize(countOfBytesCopiedFromCurrentPacket);
36083610
}
36093611

3610-
internal void ClearSnapshotDataSize()
3611-
{
3612-
Debug.Assert(_snapshot != null, "_snapshot must exist to store packet data size");
3613-
_snapshot?.ClearPacketDataSize();
3614-
}
3615-
36163612
internal int GetSnapshotTotalSize()
36173613
{
36183614
Debug.Assert(_snapshot != null && _snapshot.ContinueEnabled, "_snapshot must exist to read total size");
@@ -4309,16 +4305,6 @@ internal void SetPacketDataSize(int size)
43094305
target.RunningDataSize = total + size;
43104306
}
43114307

4312-
internal void ClearPacketDataSize()
4313-
{
4314-
PacketData current = _firstPacket;
4315-
while (current != null)
4316-
{
4317-
current.RunningDataSize = 0;
4318-
current = current.NextPacket;
4319-
}
4320-
}
4321-
43224308
internal int GetPacketDataOffset()
43234309
{
43244310
int offset = 0;
@@ -4368,6 +4354,9 @@ private void ClearPackets()
43684354

43694355
private void ClearState()
43704356
{
4357+
// TODO(GH-3385): Not sure what this is trying to assert, but it
4358+
// currently fails the DataReader tests.
4359+
// Debug.Assert(_storage == null);
43714360
_storage = null;
43724361
_replayStateData.Clear(_stateObj);
43734362
_continueStateData?.Clear(_stateObj, trackStack: false);

0 commit comments

Comments
 (0)