To implement this feature on such a low level is a disaster waiting to
happen. Remove these checks from the IO code and move them to xmllint.
Note that the serialization API will still treat "-" as stdout.
Introduce xmlXIncludeSetErrorHandler allowing to set a structured error
handler for an XInclude context and forwarding errors from parser.
Remove arguments from memory error handlers.
Use xmlRaiseMemoryError.
Also make text inclusions work with memory buffers, for example when
using a custom entity loader, and fix a memory leak in case of invalid
characters.
Fixes#483.
Avoids resource exhaustion if the maximum recursion depth was exceeded.
Note that the XInclude engine offers no protection against other
"billion laughs"-style amplification attacks as long as they stay below
the maximum depth.
When using xmlreader, XPointer expressions in XIncludes simply cannot
work. Expressions can reference nodes which weren't parsed yet or which
were already deleted.
After fixing nested XIncludes, we reference includes which were parsed
previously. When streaming, these nodes could have been deleted, leading
to use-after-free errors.
Disallow XPointer expressions and truncate the include table in
streaming mode.
Only scan new includes in the second pass. Always reset the "replace"
flag.
This only matters if xmlXIncludeDoProcess is called multiple times on
the same document which currently only happens when called from
xmlreader.
Don't create subcontext in xmlXIncludeRecurseDoc. Save and restore 'doc'
and 'incTab' instead.
Make xmlXIncludeLoadFallback call xmlXIncludeCopyNode which seems safer
than xmlXIncludeDoProcess since the latter may modify the document.
This should also be more performant since we need to copy the whole
fallback subtree anyway. Also make sure to avoid replacements in
fallback elements in xmlXIncludeDoProcess.
Use a single cache stored in the "root" context, avoiding cache misses
in some scenarios. Separate the cache from the "include" table. Rework
recursion check.
xinclude.c used to implement a refcounting mechanism for documents which
could result in documents being freed too early and reloaded. We really
should keep parsed and processed documents around for as long as
possible to avoid reprocessing.
All includes should already be expanded after calling
xmlXIncludeRecurseDoc, so there's no need to invoke the more costly
xmlXIncludeCopyNodeList. Now xmlXIncludeCopyNode is only used to copy
XPointer fragments.