From 077acbca45260ccbe65c4f4805eebbc1a14bb37d Mon Sep 17 00:00:00 2001 From: Bradley Grainger Date: Sat, 10 Apr 2021 17:47:11 -0700 Subject: [PATCH] Fix OverflowException reading OkPayload. Fixes #966 --- src/MySqlConnector/Core/ResultSet.cs | 2 +- src/MySqlConnector/MySqlDataReader.cs | 4 ++-- src/MySqlConnector/Protocol/Payloads/OkPayload.cs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/MySqlConnector/Core/ResultSet.cs b/src/MySqlConnector/Core/ResultSet.cs index 63ceb81b9..a3d01a85b 100644 --- a/src/MySqlConnector/Core/ResultSet.cs +++ b/src/MySqlConnector/Core/ResultSet.cs @@ -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; } diff --git a/src/MySqlConnector/MySqlDataReader.cs b/src/MySqlConnector/MySqlDataReader.cs index 4fee49d6c..0d1e35a6a 100644 --- a/src/MySqlConnector/MySqlDataReader.cs +++ b/src/MySqlConnector/MySqlDataReader.cs @@ -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); @@ -653,7 +653,7 @@ private ResultSet GetResultSet() readonly IDictionary? m_cachedProcedures; CommandListPosition m_commandListPosition; bool m_closed; - int? m_recordsAffected; + ulong? m_recordsAffected; bool m_hasWarnings; ResultSet? m_resultSet; bool m_hasMoreResults; diff --git a/src/MySqlConnector/Protocol/Payloads/OkPayload.cs b/src/MySqlConnector/Protocol/Payloads/OkPayload.cs index c2aafc323..65bc2f1a2 100644 --- a/src/MySqlConnector/Protocol/Payloads/OkPayload.cs +++ b/src/MySqlConnector/Protocol/Payloads/OkPayload.cs @@ -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; } @@ -32,7 +32,7 @@ public static OkPayload Create(ReadOnlySpan 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(); @@ -96,7 +96,7 @@ public static OkPayload Create(ReadOnlySpan 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;