浏览代码

LibWeb: Reject improperly encoded XML documents as not well-formed

Idan Horowitz 1 年之前
父节点
当前提交
9677d8eeac
共有 1 个文件被更改,包括 3 次插入0 次删除
  1. 3 0
      Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp

+ 3 - 0
Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp

@@ -159,6 +159,9 @@ bool build_xml_document(DOM::Document& document, ByteBuffer const& data, Optiona
         decoder = TextCodec::decoder_for(encoding);
         decoder = TextCodec::decoder_for(encoding);
     }
     }
     VERIFY(decoder.has_value());
     VERIFY(decoder.has_value());
+    // Well-formed XML documents contain only properly encoded characters
+    if (!decoder->validate(data))
+        return false;
     auto source = decoder->to_utf8(data).release_value_but_fixme_should_propagate_errors();
     auto source = decoder->to_utf8(data).release_value_but_fixme_should_propagate_errors();
     XML::Parser parser(source, { .resolve_external_resource = resolve_xml_resource });
     XML::Parser parser(source, { .resolve_external_resource = resolve_xml_resource });
     XMLDocumentBuilder builder { document };
     XMLDocumentBuilder builder { document };