File tree Expand file tree Collapse file tree
lib/public/Collaboration/Reference Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -193,7 +193,7 @@ private function fetchReference(Reference $reference): void {
193193 $ bodyStream = new LimitStream ($ stream , self ::MAX_CONTENT_LENGTH , 0 );
194194 $ content = $ bodyStream ->getContents ();
195195
196- if ($ contentType === 'image/svg+xml ' && stripos ( html_entity_decode ( $ content, ENT_XML1 ), ' XSL/Transform ' ) !== false ) {
196+ if ($ contentType === 'image/svg+xml ' && $ this -> containsXslt ( $ content) ) {
197197 return ;
198198 }
199199
@@ -230,4 +230,30 @@ public function getCacheKey(string $referenceId): ?string {
230230 public function getCacheKeyPublic (string $ referenceId , string $ sharingToken ): ?string {
231231 return null ;
232232 }
233+
234+ /**
235+ * Check if XML content contains XSLT transformations
236+ *
237+ * XSLT transformations in SVG files can cause memory exhaustion
238+ * in Chromium based browsers when rendered.
239+ */
240+ private function containsXslt (string $ xmlContent ): bool {
241+ set_error_handler (function (int $ code , string $ message ): bool {
242+ $ this ->logger ->debug ('Failed to parse XML content for XSLT check ' , ['error ' => $ message ]);
243+ return true ;
244+ });
245+
246+ $ xml = simplexml_load_string ($ xmlContent );
247+
248+ restore_error_handler ();
249+
250+ $ namespaces = $ xml ? $ xml ->getNamespaces (true ) : [];
251+ foreach ($ namespaces as $ namespace ) {
252+ if (stripos ($ namespace , 'XSL/Transform ' ) !== false ) {
253+ return true ;
254+ }
255+ }
256+
257+ return false ;
258+ }
233259}
You can’t perform that action at this time.
0 commit comments