Skip to content

Commit cb2bb16

Browse files
committed
Fix exception when incorrect parameters are supplied.
Signed-off-by: Bradley Grainger <[email protected]>
1 parent d74a1d7 commit cb2bb16

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/MySqlConnector/Core/SingleCommandPayloadCreator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ public async ValueTask WritePrologueAsync(MySqlConnection connection, CommandLis
2828
for (var i = 0; i < parameters.Length; i++)
2929
{
3030
// look up this parameter in the command's parameter collection and check if it is a Stream
31+
// NOTE: full parameter checks will be performed (and throw any necessary exceptions) in WritePreparedStatement
3132
var parameterName = preparedStatement.Statement.NormalizedParameterNames![i];
3233
var parameterIndex = parameterName is not null ? (command.RawParameters?.UnsafeIndexOf(parameterName) ?? -1) : preparedStatement.Statement.ParameterIndexes[i];
33-
if (parameterIndex != -1 && command.RawParameters![parameterIndex] is { Value: Stream stream and not MemoryStream })
34+
if (command.RawParameters is { } rawParameters && parameterIndex >= 0 && parameterIndex < rawParameters.Count && rawParameters[parameterIndex] is { Value: Stream stream and not MemoryStream })
3435
{
3536
// send almost-full packets, but don't send exactly ProtocolUtility.MaxPacketSize bytes in one payload (as that's ambiguous to whether another packet follows).
3637
const int maxDataSize = 16_000_000;

0 commit comments

Comments
 (0)