rikimaru0345 / Ceras

Universal binary serializer for a wide variety of scenarios https://discord.gg/FGaCX4c
MIT License
484 stars 53 forks source link

How to serialize DataSets / DataTables? #82

Open theRainbird opened 4 years ago

theRainbird commented 4 years ago

Describe the bug

How to reproduce the bug Here is my example code to reproduce the issue:

        var dataSet = new DataSet("TestDataSet");
        var table = new DataTable("Person");
        var personIDColumn = table.Columns.Add("PersonID", typeof(int));
        personIDColumn.AutoIncrement = true;
        personIDColumn.AutoIncrementSeed = -1;
        personIDColumn.AutoIncrementStep = -1;
        table.Columns.Add("FirstName", typeof(string));
        table.Columns.Add("LastName", typeof(string));
        table.PrimaryKey = new DataColumn[] {personIDColumn};
        dataSet.Tables.Add(table);
        var row = table.NewRow();
        row["FirstName"] = "Max";
        row["LastName"] = "Mustermann";
        table.Rows.Add(row);
        row.AcceptChanges();
        row["FirstName"] = "Maxine";            
        var ceras = new CerasSerializer();            
        byte[] raw = ceras.Serialize(dataSet);
        var dataSet2 = ceras.Deserialize<DataSet>(raw);            
        Console.WriteLine(dataSet2.Tables["Person"].Rows[0].RowState);
        Console.WriteLine(dataSet2.Tables["Person"].Rows[0]["FirstName"]);
        Console.WriteLine(dataSet2.Tables["Person"].Rows[0]["FirstName", DataRowVersion.Original]);

Platform

rikimaru0345 commented 4 years ago

I don't care if DataSets are rated bad or insecure by some people, because I have large applications with a big code base that I don't want to write from scratch.

Ok, whatever, I won't stand in your way 😝

You can compile the code yourself, comment out the corrosponding part here:

https://github.com/rikimaru0345/Ceras/blob/master/src/Ceras/Helpers/BannedTypes.cs#L74

But it is not a bug, the concern is valid. If you add a setting that enables one to turn off those bans, I'd merge it (assuming it is off by default).

theRainbird commented 4 years ago

Thank you so much.
This will help.

Sorry for tagging this issue as bug. You're right, DataSet serialization has security issues and so it should only be used in a trusted environment and never exposed to the Internet.

I'll try to extend settings with a "AllowDataSetSerialization" property, which is set false by default.

andreasmaier-abt commented 4 years ago

I am going to second this request. I actually have a large number of applications that make use of large datatables and being able to cache these in something like redis would really help. I tried to muck with the BannedTypes but ran already into issues serializing CultureInfo. So an effort on DataTable would really be appreciated.

rikimaru0345 commented 4 years ago

@andreasmaier-abt Alright, noted. I'll add it to my todo list. But but it's probably going to take a while before I can make time to work on Ceras again (sorry ☹️).

but ran already into issues serializing CultureInfo.

What exactly is the problem with CultureInfo? I never really worked with it, but after looking at: https://docs.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.-ctor?view=netframework-4.8#System_Globalization_CultureInfo__ctor_System_Int32_ it seems like its basically just an int.

But if someone creates their own CultureInfo (based on some existing one and then just changing some properties), it's a little bit more complicated to serialize.

Anyway, whatever the issue with it is, adding support for it in Ceras is most likely very easy.