Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

GetInt32Core throws OverflowException for valid data in prepared statements (regression from 0.57) #1018

Copy link
Copy link
Closed
@weltkante

Description

@weltkante
Issue body actions

I've been intending to update our usage of the MySqlConnector package (we were still on the 0.x versions) but when going to anything newer than 1.2.1 (i.e. anything on the 1.3.x or 1.4.x version series) I'm getting OverflowExceptions from GetInt32Core which I wasn't getting before.

I'm calling MySqlDataReader.GetInt32, the column in the table is int NOT NULL and the row causing the exception contains the value 300 which presumably should fit into an integer (at least it did work in earlier releases of the connector).

When it breaks into the debugger I see GetInt32Core is trying to parse an empty span as UTF8 and when looking up the call stack the row seems to think its a TextRow but its contained data looks binary.

repro code
using System.Data.Common;
using System.IO;
using MySqlConnector;

class Program
{
    static void Main(string[] args)
    {
        var cs = new MySqlConnectionStringBuilder();
        cs.Server = "127.0.0.1";
        cs.Database = "sandbox";

        using var conn = new MySqlConnection(cs.ToString());
        conn.Open();

        PrepareIssue(conn);

        using var cmd = conn.CreateCommand();
        cmd.CommandText = ""
            + " SELECT account, id, name, data1, data2, data3, flags, ts1, ts2, ts3, ts4 "
            + " FROM info "
            + " WHERE id = @id AND ts4 is null ";
        cmd.Prepare();
        cmd.Parameters.Add("@id", MySqlDbType.Int32);
        cmd.Parameters["@id"].Value = 174;

        using var reader = cmd.ExecuteReader();
        if (!reader.Read())
            throw new InvalidDataException("Invalid test data provided.");

        var value = reader.GetInt32(0);
        if (value != 300)
            throw new InvalidDataException("Invalid test data provided.");
    }

    static void PrepareIssue(DbConnection conn)
    {
        using var cmd = conn.CreateCommand();

        cmd.CommandText = "DROP TABLE IF EXISTS info";

        cmd.ExecuteNonQuery();

        cmd.CommandText = "" +
            " CREATE TABLE info (" +
            "   id int NOT NULL AUTO_INCREMENT," +
            "   account int NOT NULL," +
            "   name varchar(32) NOT NULL," +
            "   flags int NOT NULL," +
            "   data1 int NOT NULL," +
            "   data2 int NOT NULL," +
            "   data3 int NOT NULL DEFAULT '1'," +
            "   ts1 timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP," +
            "   ts2 timestamp NULL DEFAULT NULL," +
            "   ts3 timestamp NULL DEFAULT NULL," +
            "   ts4 timestamp NULL DEFAULT NULL," +
            "   PRIMARY KEY (id)" +
            " )";

        cmd.ExecuteNonQuery();

        cmd.CommandText = "INSERT INTO info (id, account, name, flags, data1, data2, data3, ts1, ts2, ts3, ts4)" +
            " VALUES ('174', '300', 'xxxxxxxxxx', '0', '273', '185343498', '14', '2020-01-01 12:34:56', NULL, NULL, NULL)";

        cmd.ExecuteNonQuery();
    }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.