Disable various unused libxml features: catalogs, DocBook, legacy APIs, etc.

See third_party/libxml/README.chromium for the list.

BUG=604167

Review-Url: https://codereview.chromium.org/2788063002
Cr-Commit-Position: refs/heads/master@{#461657}
diff --git a/testing/libfuzzer/fuzzers/BUILD.gn b/testing/libfuzzer/fuzzers/BUILD.gn
index 217e08b..d0d323e 100644
--- a/testing/libfuzzer/fuzzers/BUILD.gn
+++ b/testing/libfuzzer/fuzzers/BUILD.gn
@@ -353,17 +353,6 @@
   libfuzzer_options = [ "max_len=500" ]
 }
 
-fuzzer_test("libxml_xml_regexp_compile_fuzzer") {
-  sources = [
-    "libxml_xml_regexp_compile_fuzzer.cc",
-  ]
-  deps = [
-    "//third_party/libxml",
-  ]
-  libfuzzer_options = [ "max_len=32" ]
-  additional_configs = [ "//testing/libfuzzer:no_clusterfuzz" ]
-}
-
 fuzzer_test("convert_woff2ttf_fuzzer") {
   sources = [
     "convert_woff2ttf_fuzzer.cc",
diff --git a/testing/libfuzzer/fuzzers/libxml_xml_regexp_compile_fuzzer.cc b/testing/libfuzzer/fuzzers/libxml_xml_regexp_compile_fuzzer.cc
deleted file mode 100644
index 65aba29..0000000
--- a/testing/libfuzzer/fuzzers/libxml_xml_regexp_compile_fuzzer.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include <algorithm>
-#include <string>
-#include <vector>
-
-#include "libxml/parser.h"
-#include "libxml/tree.h"
-#include "libxml/xmlversion.h"
-
-
-void ignore (void * ctx, const char * msg, ...) {
-  // Error handler to avoid spam of error messages from libxml parser.
-}
-
-
-// Entry point for LibFuzzer.
-extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
-  xmlSetGenericErrorFunc(NULL, &ignore);
-
-  std::vector<uint8_t> buffer(size + 1, 0);
-  std::copy(data, data + size, buffer.data());
-
-  xmlRegexpPtr x = xmlRegexpCompile(buffer.data());
-  if (x)
-    xmlRegFreeRegexp(x);
-
-  return 0;
-}
diff --git a/third_party/WebKit/Source/core/xml/parser/XMLDocumentParser.cpp b/third_party/WebKit/Source/core/xml/parser/XMLDocumentParser.cpp
index 66389374..f14e8c3 100644
--- a/third_party/WebKit/Source/core/xml/parser/XMLDocumentParser.cpp
+++ b/third_party/WebKit/Source/core/xml/parser/XMLDocumentParser.cpp
@@ -26,7 +26,6 @@
 
 #include "core/xml/parser/XMLDocumentParser.h"
 
-#include <libxml/catalog.h>
 #include <libxml/parser.h>
 #include <libxml/parserInternals.h>
 #include <libxslt/xslt.h>
@@ -572,12 +571,13 @@
   #error "Use parseChunk instead to select the correct encoding."
 
 static bool isLibxmlDefaultCatalogFile(const String& urlString) {
-  // On non-Windows platforms libxml asks for this URL, the
-  // "XML_XML_DEFAULT_CATALOG", on initialization.
+  // On non-Windows platforms libxml with catalogs enabled asks for
+  // this URL, the "XML_XML_DEFAULT_CATALOG", on initialization.
   if (urlString == "file:///etc/xml/catalog")
     return true;
 
-  // On Windows, libxml computes a URL relative to where its DLL resides.
+  // On Windows, libxml with catalogs enabled computes a URL relative
+  // to where its DLL resides.
   if (urlString.startsWith("file:///", TextCaseASCIIInsensitive) &&
       urlString.endsWith("/etc/catalog", TextCaseASCIIInsensitive))
     return true;
@@ -587,10 +587,9 @@
 static bool shouldAllowExternalLoad(const KURL& url) {
   String urlString = url.getString();
 
-  // This isn't really necessary now that initializeLibXMLIfNecessary
-  // disables catalog support in libxml, but keeping it for defense in depth.
-  if (isLibxmlDefaultCatalogFile(url))
-    return false;
+  // libxml should not be configured with catalogs enabled, so it
+  // should not be asking to load default catalogs.
+  CHECK(!isLibxmlDefaultCatalogFile(url));
 
   // The most common DTD. There isn't much point in hammering www.w3c.org by
   // requesting this URL for every XHTML document.
@@ -697,10 +696,6 @@
   if (didInit)
     return;
 
-  // We don't want libxml to try and load catalogs.
-  // FIXME: It's not nice to set global settings in libxml, embedders of Blink
-  // could be trying to use libxml themselves.
-  xmlCatalogSetDefaults(XML_CATA_ALLOW_NONE);
   xmlInitParser();
   xmlRegisterInputCallbacks(matchFunc, openFunc, readFunc, closeFunc);
   xmlRegisterOutputCallbacks(matchFunc, openFunc, writeFunc, closeFunc);
diff --git a/third_party/libxml/BUILD.gn b/third_party/libxml/BUILD.gn
index 147455b..41c0fa7 100644
--- a/third_party/libxml/BUILD.gn
+++ b/third_party/libxml/BUILD.gn
@@ -78,17 +78,17 @@
     "linux/include/libxml/xmlversion.h",
     "mac/config.h",
     "mac/include/libxml/xmlversion.h",
-    "src/DOCBparser.c",
+    #"src/DOCBparser.c",
     "src/HTMLparser.c",
     "src/HTMLtree.c",
-    "src/SAX.c",
+    #"src/SAX.c",
     "src/SAX2.c",
     "src/buf.c",
     "src/buf.h",
-    "src/c14n.c",
-    "src/catalog.c",
+    #"src/c14n.c",
+    #"src/catalog.c",
     "src/chvalid.c",
-    "src/debugXML.c",
+    #"src/debugXML.c",
     "src/dict.c",
     "src/elfgcchack.h",
     "src/enc.h",
@@ -145,21 +145,20 @@
     "src/include/libxml/xpointer.h",
     "src/include/win32config.h",
     "src/include/wsockcompat.h",
-    "src/legacy.c",
+    #"src/legacy.c",
     "src/libxml.h",
     "src/list.c",
     "src/parser.c",
     "src/parserInternals.c",
     "src/pattern.c",
-    "src/relaxng.c",
+    #"src/relaxng.c",
     "src/save.h",
-    "src/schematron.c",
+    #"src/schematron.c",
     "src/threads.c",
     "src/timsort.h",
     "src/tree.c",
     "src/triodef.h",
     "src/trionan.h",
-
     #"src/trio.c",
     #"src/trio.h",
     #"src/triodef.h",
@@ -170,22 +169,21 @@
     #"src/triostr.h",
     "src/uri.c",
     "src/valid.c",
-    "src/xinclude.c",
-    "src/xlink.c",
+    #"src/xinclude.c",
+    #"src/xlink.c",
     "src/xmlIO.c",
     "src/xmlmemory.c",
-    "src/xmlmodule.c",
+    #"src/xmlmodule.c",
     "src/xmlreader.c",
-    "src/xmlregexp.c",
+    #"src/xmlregexp.c",
     "src/xmlsave.c",
-    "src/xmlschemas.c",
-    "src/xmlschemastypes.c",
+    #"src/xmlschemas.c",
+    #"src/xmlschemastypes.c",
     "src/xmlstring.c",
     "src/xmlunicode.c",
     "src/xmlwriter.c",
     "src/xpath.c",
-    "src/xpointer.c",
-
+    #"src/xpointer.c",
     #"src/xzlib.c",
     "src/xzlib.h",
     "win32/config.h",
diff --git a/third_party/libxml/README.chromium b/third_party/libxml/README.chromium
index 0541a47..392a11a 100644
--- a/third_party/libxml/README.chromium
+++ b/third_party/libxml/README.chromium
@@ -18,7 +18,21 @@
 - Apply patch contributed here: https://crbug.com/683629#c9
 - Modify win32/include/libxml/xmlversion.h, mac/include/libxml/xmlversion.h and
   linux/include/libxml/xmlversion.h to not define these:
-  LIBXML_SCHEMAS_ENABLED, LIBXML_VALID_ENABLED, LIBXML_XINCLUDE_ENABLED
+  LIBXML_AUTOMATA_ENABLED
+  LIBXML_C14N_ENABLED
+  LIBXML_CATALOG_ENABLED
+  LIBXML_DEBUG_ENABLED
+  LIBXML_DOCB_ENABLED
+  LIBXML_EXPR_ENABLED
+  LIBXML_LEGACY_ENABLED
+  LIBXML_MODULES_ENABLED
+  LIBXML_REGEXP_ENABLED
+  LIBXML_SCHEMAS_ENABLED
+  LIBXML_SCHEMATRON_ENABLED
+  LIBXML_VALID_ENABLED
+  LIBXML_XINCLUDE_ENABLED
+  LIBXML_XPTR_ENABLED
+  LIBXML_ZLIB_ENABLED
 
 This import was generated by this script:
 https://github.com/dominiccooney/blink-tools/blob/ac9f8e093ec3d00267d67927a37956e5e8993961/roll.py
diff --git a/third_party/libxml/linux/include/libxml/xmlversion.h b/third_party/libxml/linux/include/libxml/xmlversion.h
index 5a59c80d..18ff5ff0 100644
--- a/third_party/libxml/linux/include/libxml/xmlversion.h
+++ b/third_party/libxml/linux/include/libxml/xmlversion.h
@@ -210,7 +210,7 @@
  *
  * Whether the deprecated APIs are compiled in for compatibility
  */
-#if 1
+#if 0
 #define LIBXML_LEGACY_ENABLED
 #endif
 
@@ -219,7 +219,7 @@
  *
  * Whether the Canonicalization support is configured in
  */
-#if 1
+#if 0
 #define LIBXML_C14N_ENABLED
 #endif
 
@@ -228,7 +228,7 @@
  *
  * Whether the Catalog support is configured in
  */
-#if 1
+#if 0
 #define LIBXML_CATALOG_ENABLED
 #endif
 
@@ -237,7 +237,7 @@
  *
  * Whether the SGML Docbook support is configured in
  */
-#if 1
+#if 0
 #define LIBXML_DOCB_ENABLED
 #endif
 
@@ -255,7 +255,7 @@
  *
  * Whether XPointer is configured in
  */
-#if 1
+#if 0
 #define LIBXML_XPTR_ENABLED
 #endif
 
@@ -300,7 +300,7 @@
  *
  * Whether Debugging module is configured in
  */
-#if 1
+#if 0
 #define LIBXML_DEBUG_ENABLED
 #endif
 
@@ -336,7 +336,7 @@
  *
  * Whether the regular expressions interfaces are compiled in
  */
-#if 1
+#if 0
 #define LIBXML_REGEXP_ENABLED
 #endif
 
@@ -345,7 +345,7 @@
  *
  * Whether the automata interfaces are compiled in
  */
-#if 1
+#if 0
 #define LIBXML_AUTOMATA_ENABLED
 #endif
 
@@ -354,7 +354,7 @@
  *
  * Whether the formal expressions interfaces are compiled in
  */
-#if 1
+#if 0
 #define LIBXML_EXPR_ENABLED
 #endif
 
@@ -372,7 +372,7 @@
  *
  * Whether the Schematron validation interfaces are compiled in
  */
-#if 1
+#if 0
 #define LIBXML_SCHEMATRON_ENABLED
 #endif
 
@@ -381,7 +381,7 @@
  *
  * Whether the module interfaces are compiled in
  */
-#if 1
+#if 0
 #define LIBXML_MODULES_ENABLED
 /**
  * LIBXML_MODULE_EXTENSION:
@@ -396,7 +396,7 @@
  *
  * Whether the Zlib support is compiled in
  */
-#if 1
+#if 0
 #define LIBXML_ZLIB_ENABLED
 #endif
 
diff --git a/third_party/libxml/mac/include/libxml/xmlversion.h b/third_party/libxml/mac/include/libxml/xmlversion.h
index 5a59c80d..18ff5ff0 100644
--- a/third_party/libxml/mac/include/libxml/xmlversion.h
+++ b/third_party/libxml/mac/include/libxml/xmlversion.h
@@ -210,7 +210,7 @@
  *
  * Whether the deprecated APIs are compiled in for compatibility
  */
-#if 1
+#if 0
 #define LIBXML_LEGACY_ENABLED
 #endif
 
@@ -219,7 +219,7 @@
  *
  * Whether the Canonicalization support is configured in
  */
-#if 1
+#if 0
 #define LIBXML_C14N_ENABLED
 #endif
 
@@ -228,7 +228,7 @@
  *
  * Whether the Catalog support is configured in
  */
-#if 1
+#if 0
 #define LIBXML_CATALOG_ENABLED
 #endif
 
@@ -237,7 +237,7 @@
  *
  * Whether the SGML Docbook support is configured in
  */
-#if 1
+#if 0
 #define LIBXML_DOCB_ENABLED
 #endif
 
@@ -255,7 +255,7 @@
  *
  * Whether XPointer is configured in
  */
-#if 1
+#if 0
 #define LIBXML_XPTR_ENABLED
 #endif
 
@@ -300,7 +300,7 @@
  *
  * Whether Debugging module is configured in
  */
-#if 1
+#if 0
 #define LIBXML_DEBUG_ENABLED
 #endif
 
@@ -336,7 +336,7 @@
  *
  * Whether the regular expressions interfaces are compiled in
  */
-#if 1
+#if 0
 #define LIBXML_REGEXP_ENABLED
 #endif
 
@@ -345,7 +345,7 @@
  *
  * Whether the automata interfaces are compiled in
  */
-#if 1
+#if 0
 #define LIBXML_AUTOMATA_ENABLED
 #endif
 
@@ -354,7 +354,7 @@
  *
  * Whether the formal expressions interfaces are compiled in
  */
-#if 1
+#if 0
 #define LIBXML_EXPR_ENABLED
 #endif
 
@@ -372,7 +372,7 @@
  *
  * Whether the Schematron validation interfaces are compiled in
  */
-#if 1
+#if 0
 #define LIBXML_SCHEMATRON_ENABLED
 #endif
 
@@ -381,7 +381,7 @@
  *
  * Whether the module interfaces are compiled in
  */
-#if 1
+#if 0
 #define LIBXML_MODULES_ENABLED
 /**
  * LIBXML_MODULE_EXTENSION:
@@ -396,7 +396,7 @@
  *
  * Whether the Zlib support is compiled in
  */
-#if 1
+#if 0
 #define LIBXML_ZLIB_ENABLED
 #endif
 
diff --git a/third_party/libxml/win32/include/libxml/xmlversion.h b/third_party/libxml/win32/include/libxml/xmlversion.h
index 337ee3b..bcf0b35 100644
--- a/third_party/libxml/win32/include/libxml/xmlversion.h
+++ b/third_party/libxml/win32/include/libxml/xmlversion.h
@@ -210,7 +210,7 @@
  *
  * Whether the deprecated APIs are compiled in for compatibility
  */
-#if 1
+#if 0
 #define LIBXML_LEGACY_ENABLED
 #endif
 
@@ -219,7 +219,7 @@
  *
  * Whether the Canonicalization support is configured in
  */
-#if 1
+#if 0
 #define LIBXML_C14N_ENABLED
 #endif
 
@@ -228,7 +228,7 @@
  *
  * Whether the Catalog support is configured in
  */
-#if 1
+#if 0
 #define LIBXML_CATALOG_ENABLED
 #endif
 
@@ -237,7 +237,7 @@
  *
  * Whether the SGML Docbook support is configured in
  */
-#if 1
+#if 0
 #define LIBXML_DOCB_ENABLED
 #endif
 
@@ -255,7 +255,7 @@
  *
  * Whether XPointer is configured in
  */
-#if 1
+#if 0
 #define LIBXML_XPTR_ENABLED
 #endif
 
@@ -291,7 +291,7 @@
  *
  * Whether ISO-8859-* support is made available in case iconv is not
  */
-#if 0
+#if 1
 #define LIBXML_ISO8859X_ENABLED
 #endif
 
@@ -300,7 +300,7 @@
  *
  * Whether Debugging module is configured in
  */
-#if 1
+#if 0
 #define LIBXML_DEBUG_ENABLED
 #endif
 
@@ -336,7 +336,7 @@
  *
  * Whether the regular expressions interfaces are compiled in
  */
-#if 1
+#if 0
 #define LIBXML_REGEXP_ENABLED
 #endif
 
@@ -345,7 +345,7 @@
  *
  * Whether the automata interfaces are compiled in
  */
-#if 1
+#if 0
 #define LIBXML_AUTOMATA_ENABLED
 #endif
 
@@ -354,7 +354,7 @@
  *
  * Whether the formal expressions interfaces are compiled in
  */
-#if 1
+#if 0
 #define LIBXML_EXPR_ENABLED
 #endif
 
@@ -372,7 +372,7 @@
  *
  * Whether the Schematron validation interfaces are compiled in
  */
-#if 1
+#if 0
 #define LIBXML_SCHEMATRON_ENABLED
 #endif
 
@@ -381,7 +381,7 @@
  *
  * Whether the module interfaces are compiled in
  */
-#if 1
+#if 0
 #define LIBXML_MODULES_ENABLED
 /**
  * LIBXML_MODULE_EXTENSION: