Skip to content

Commit

Permalink
Validate serialized resource data format when writing
Browse files Browse the repository at this point in the history
  • Loading branch information
ElektroKill committed Jul 10, 2023
1 parent e636c16 commit 451e8f9
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/DotNet/Resources/UserResourceData.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// dnlib: See LICENSE.txt for more info

using System;
using System.IO;
using System.Runtime.Serialization;
using dnlib.IO;
Expand Down Expand Up @@ -68,6 +69,8 @@ public BinaryResourceData(UserResourceType type, byte[] data, SerializationForma

/// <inheritdoc/>
public override void WriteData(ResourceBinaryWriter writer, IFormatter formatter) {
if (writer.ReaderType == ResourceReaderType.ResourceReader && Format != SerializationFormat.BinaryFormatter)
throw new NotSupportedException();
if (writer.ReaderType == ResourceReaderType.DeserializingResourceReader) {
writer.Write7BitEncodedInt((int)format);
writer.Write7BitEncodedInt(data.Length);
Expand Down

0 comments on commit 451e8f9

Please sign in to comment.