Skip to content

Commit

Permalink
Fix OverflowException reading OkPayload. Fixes #966
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrainger committed Apr 11, 2021
1 parent d1ed1c2 commit 077acbc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/MySqlConnector/Core/ResultSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public Row GetCurrentRow()
public ColumnDefinitionPayload[]? ColumnDefinitions { get; private set; }
public MySqlDbType[]? ColumnTypes { get; private set; }
public long LastInsertId { get; private set; }
public int? RecordsAffected { get; private set; }
public ulong? RecordsAffected { get; private set; }
public int WarningCount { get; private set; }
public ResultSetState State { get; private set; }
public bool ContainsCommandParameters { get; private set; }
Expand Down
4 changes: 2 additions & 2 deletions src/MySqlConnector/MySqlDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public override bool HasRows
}

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

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

Expand Down Expand Up @@ -653,7 +653,7 @@ private ResultSet GetResultSet()
readonly IDictionary<string, CachedProcedure?>? m_cachedProcedures;
CommandListPosition m_commandListPosition;
bool m_closed;
int? m_recordsAffected;
ulong? m_recordsAffected;
bool m_hasWarnings;
ResultSet? m_resultSet;
bool m_hasMoreResults;
Expand Down
6 changes: 3 additions & 3 deletions src/MySqlConnector/Protocol/Payloads/OkPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace MySqlConnector.Protocol.Payloads
{
internal sealed class OkPayload
{
public int AffectedRowCount { get; }
public ulong AffectedRowCount { get; }
public ulong LastInsertId { get; }
public ServerStatus ServerStatus { get; }
public int WarningCount { get; }
Expand All @@ -32,7 +32,7 @@ public static OkPayload Create(ReadOnlySpan<byte> span, bool deprecateEof, bool
var signature = reader.ReadByte();
if (signature != Signature && (!deprecateEof || signature != EofPayload.Signature))
throw new FormatException("Expected to read 0x00 or 0xFE but got 0x{0:X2}".FormatInvariant(signature));
var affectedRowCount = checked((int) reader.ReadLengthEncodedInteger());
var affectedRowCount = reader.ReadLengthEncodedInteger();
var lastInsertId = reader.ReadLengthEncodedInteger();
var serverStatus = (ServerStatus) reader.ReadUInt16();
var warningCount = (int) reader.ReadUInt16();
Expand Down Expand Up @@ -96,7 +96,7 @@ public static OkPayload Create(ReadOnlySpan<byte> span, bool deprecateEof, bool
return new OkPayload(affectedRowCount, lastInsertId, serverStatus, warningCount, statusInfo, newSchema);
}

private OkPayload(int affectedRowCount, ulong lastInsertId, ServerStatus serverStatus, int warningCount, string? statusInfo, string? newSchema)
private OkPayload(ulong affectedRowCount, ulong lastInsertId, ServerStatus serverStatus, int warningCount, string? statusInfo, string? newSchema)
{
AffectedRowCount = affectedRowCount;
LastInsertId = lastInsertId;
Expand Down

0 comments on commit 077acbc

Please sign in to comment.