Skip to content

Commit 077acbc

Browse files
committed
Fix OverflowException reading OkPayload. Fixes #966
1 parent d1ed1c2 commit 077acbc

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/MySqlConnector/Core/ResultSet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public Row GetCurrentRow()
435435
public ColumnDefinitionPayload[]? ColumnDefinitions { get; private set; }
436436
public MySqlDbType[]? ColumnTypes { get; private set; }
437437
public long LastInsertId { get; private set; }
438-
public int? RecordsAffected { get; private set; }
438+
public ulong? RecordsAffected { get; private set; }
439439
public int WarningCount { get; private set; }
440440
public ResultSetState State { get; private set; }
441441
public bool ContainsCommandParameters { get; private set; }

src/MySqlConnector/MySqlDataReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public override bool HasRows
211211
}
212212

213213
public override bool IsClosed => Command is null;
214-
public override int RecordsAffected => m_recordsAffected.GetValueOrDefault(-1);
214+
public override int RecordsAffected => m_recordsAffected.HasValue ? checked((int) m_recordsAffected) : -1;
215215

216216
public override int GetOrdinal(string name) => GetResultSet().GetOrdinal(name);
217217

@@ -653,7 +653,7 @@ private ResultSet GetResultSet()
653653
readonly IDictionary<string, CachedProcedure?>? m_cachedProcedures;
654654
CommandListPosition m_commandListPosition;
655655
bool m_closed;
656-
int? m_recordsAffected;
656+
ulong? m_recordsAffected;
657657
bool m_hasWarnings;
658658
ResultSet? m_resultSet;
659659
bool m_hasMoreResults;

src/MySqlConnector/Protocol/Payloads/OkPayload.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace MySqlConnector.Protocol.Payloads
77
{
88
internal sealed class OkPayload
99
{
10-
public int AffectedRowCount { get; }
10+
public ulong AffectedRowCount { get; }
1111
public ulong LastInsertId { get; }
1212
public ServerStatus ServerStatus { get; }
1313
public int WarningCount { get; }
@@ -32,7 +32,7 @@ public static OkPayload Create(ReadOnlySpan<byte> span, bool deprecateEof, bool
3232
var signature = reader.ReadByte();
3333
if (signature != Signature && (!deprecateEof || signature != EofPayload.Signature))
3434
throw new FormatException("Expected to read 0x00 or 0xFE but got 0x{0:X2}".FormatInvariant(signature));
35-
var affectedRowCount = checked((int) reader.ReadLengthEncodedInteger());
35+
var affectedRowCount = reader.ReadLengthEncodedInteger();
3636
var lastInsertId = reader.ReadLengthEncodedInteger();
3737
var serverStatus = (ServerStatus) reader.ReadUInt16();
3838
var warningCount = (int) reader.ReadUInt16();
@@ -96,7 +96,7 @@ public static OkPayload Create(ReadOnlySpan<byte> span, bool deprecateEof, bool
9696
return new OkPayload(affectedRowCount, lastInsertId, serverStatus, warningCount, statusInfo, newSchema);
9797
}
9898

99-
private OkPayload(int affectedRowCount, ulong lastInsertId, ServerStatus serverStatus, int warningCount, string? statusInfo, string? newSchema)
99+
private OkPayload(ulong affectedRowCount, ulong lastInsertId, ServerStatus serverStatus, int warningCount, string? statusInfo, string? newSchema)
100100
{
101101
AffectedRowCount = affectedRowCount;
102102
LastInsertId = lastInsertId;

0 commit comments

Comments
 (0)