Skip to content

Commit

Permalink
Merge pull request #2608 from haroohie-club/DontUseBinaryFormatter
Browse files Browse the repository at this point in the history
Remove BinaryFormatter from DragDropLib
  • Loading branch information
cwensley authored Jan 15, 2024
2 parents 51e1798 + b5056a9 commit 6f1b453
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Eto.Wpf/CustomControls/DragDropLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,10 @@ public static object GetManagedData(this IDataObject dataObject, string format)
if (ManagedDataStamp.Equals(guid))
{
// Stamp matched, so deserialize
BinaryFormatter formatter = new BinaryFormatter();
Type dataType = (Type)formatter.Deserialize(dataStream);
object data2 = formatter.Deserialize(dataStream);
DataContractSerializer typeSerializer = new DataContractSerializer(typeof(Type));
Type dataType = (Type)typeSerializer.ReadObject(dataStream);
DataContractSerializer objectSerializer = new DataContractSerializer(dataType);
object data2 = objectSerializer.ReadObject(dataStream);
if (data2.GetType() == dataType)
return data2;
else if (data2 is string)
Expand Down Expand Up @@ -442,9 +443,10 @@ private static void GetMediumFromObject(object data, out STGMEDIUM medium)
// we'll try type conversion. Also, we serialize the type. That way,
// during deserialization, we know which type to convert back to, if
// appropriate.
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, data.GetType());
formatter.Serialize(stream, GetAsSerializable(data));
DataContractSerializer typeSerializer = new DataContractSerializer(typeof(Type));
typeSerializer.WriteObject(stream, data.GetType());
DataContractSerializer objectSerializer = new DataContractSerializer(data.GetType());
objectSerializer.WriteObject(stream, GetAsSerializable(data));

// Now copy to an HGLOBAL
byte[] bytes = stream.GetBuffer();
Expand Down

0 comments on commit 6f1b453

Please sign in to comment.