@@ -85,9 +85,12 @@ internal void LoadFromPart(OpenXmlPart openXmlPart)
85
85
throw new ArgumentNullException ( nameof ( openXmlPart ) ) ;
86
86
}
87
87
88
+ // Accessed before stream as it may cause the stream to reload
89
+ var strictRelationshipFound = openXmlPart . OpenXmlPackage . StrictRelationshipFound ;
90
+
88
91
using ( Stream partStream = openXmlPart . GetStream ( FileMode . Open ) )
89
92
{
90
- LoadFromPart ( openXmlPart , partStream ) ;
93
+ LoadFromPart ( openXmlPart , partStream , strictRelationshipFound ) ;
91
94
}
92
95
}
93
96
@@ -96,12 +99,13 @@ internal void LoadFromPart(OpenXmlPart openXmlPart)
96
99
/// </summary>
97
100
/// <param name="openXmlPart">The part this root element to be loaded from.</param>
98
101
/// <param name="partStream">The stream of the part.</param>
102
+ /// <param name="strictRelationshipFound">Whether a strict relationship was found.</param>
99
103
/// <returns>
100
104
/// Returns true when the part stream is loaded successfully into this root element.
101
105
/// Returns false when the part stream does not contain any xml element.
102
106
/// </returns>
103
107
/// <exception cref="InvalidDataException">Thrown when the part stream contains an incorrect root element.</exception>
104
- internal bool LoadFromPart ( OpenXmlPart openXmlPart , Stream partStream )
108
+ internal bool LoadFromPart ( OpenXmlPart openXmlPart , Stream partStream , bool strictRelationshipFound )
105
109
{
106
110
if ( partStream . Length < 4 )
107
111
{
@@ -123,7 +127,7 @@ internal bool LoadFromPart(OpenXmlPart openXmlPart, Stream partStream)
123
127
context . XmlReaderSettings . DtdProcessing = DtdProcessing . Prohibit ; // set to prohibit explicitly for security fix
124
128
#endif
125
129
126
- using ( var xmlReader = XmlConvertingReaderFactory . Create ( partStream , Features . GetNamespaceResolver ( ) , context . XmlReaderSettings , openXmlPart . OpenXmlPackage . StrictRelationshipFound ) )
130
+ using ( var xmlReader = XmlConvertingReaderFactory . Create ( partStream , Features . GetNamespaceResolver ( ) , context . XmlReaderSettings , strictRelationshipFound ) )
127
131
{
128
132
context . MCSettings = openXmlPart . MCSettings ;
129
133
0 commit comments