Test for fix of issue dotnet/corefx#3408
authorimcarolwang <v-carwan@V-CARWAN05>
Mon, 24 Jun 2019 08:30:36 +0000 (01:30 -0700)
committerMatt Connew <mconnew@microsoft.com>
Mon, 24 Jun 2019 21:47:57 +0000 (14:47 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/57a2750da0bf6ac6e421dda43c468f485dba8ae0

src/libraries/System.Runtime.Serialization.Xml/tests/DataContractSerializer.cs

index 82b03d4..ef276bf 100644 (file)
@@ -4092,6 +4092,20 @@ public static partial class DataContractSerializerTests
         });
     }
 
+    [Fact]
+    public static void DCS_ReadObject_XmlDictionaryReaderMaxStringContentLengthExceedsQuota()
+    {
+        DataContractSerializer dcs = new DataContractSerializer(typeof(TypeA));
+        int maxStringContentLength = 1024;
+        var type = new TypeA { Name = "BOOM!".PadLeft(maxStringContentLength + 1, ' ') };
+        MemoryStream ms = new MemoryStream();
+        dcs.WriteObject(ms, type);
+        ms.Position = 0;
+        XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(ms, new System.Xml.XmlDictionaryReaderQuotas() { MaxStringContentLength = maxStringContentLength });
+
+        Assert.Throws<System.Runtime.Serialization.SerializationException>(() => { dcs.ReadObject(reader); });
+    }
+
     private static T DeserializeString<T>(string stringToDeserialize, bool shouldReportDeserializationExceptions = true, DataContractSerializerSettings settings = null, Func<DataContractSerializer> serializerFactory = null)
     {
         DataContractSerializer dcs;