Skip to content

Commit

Permalink
Update libxml2 to v2.12.5
Browse files Browse the repository at this point in the history
  • Loading branch information
beutlich committed Mar 8, 2024
1 parent fc402d0 commit defc777
Show file tree
Hide file tree
Showing 25 changed files with 337 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ before_install:
esac
- curl https://bitbucket.org/Swyter/bitbucket-curl-upload-to-repo-downloads/raw/default/upload-to-bitbucket.sh -O -J -L
- chmod +x ./upload-to-bitbucket.sh
- git clone --branch v2.12.0 --depth 1 https://gitlab.gnome.org/GNOME/libxml2
- git clone --branch v2.12.5 --depth 1 https://gitlab.gnome.org/GNOME/libxml2
- mkdir -p libxml2/$PLATFORM

before_cache:
Expand Down
21 changes: 20 additions & 1 deletion ExternData/Resources/C-Sources/libxml2/HTMLparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -4851,6 +4851,14 @@ htmlParseDocument(htmlParserCtxtPtr ctxt) {

xmlDetectEncoding(ctxt);

/*
* This is wrong but matches long-standing behavior. In most cases,
* a document starting with an XML declaration will specify UTF-8.
*/
if (((ctxt->input->flags & XML_INPUT_HAS_ENCODING) == 0) &&
(xmlStrncmp(ctxt->input->cur, BAD_CAST "<?xm", 4) == 0))
xmlSwitchEncoding(ctxt, XML_CHAR_ENCODING_UTF8);

/*
* Wipe out everything which is before the first '<'
*/
Expand Down Expand Up @@ -5408,6 +5416,16 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
*/
goto done;
case XML_PARSER_START:
/*
* This is wrong but matches long-standing behavior. In most
* cases, a document starting with an XML declaration will
* specify UTF-8.
*/
if (((ctxt->input->flags & XML_INPUT_HAS_ENCODING) == 0) &&
(xmlStrncmp(ctxt->input->cur, BAD_CAST "<?xm", 4) == 0)) {
xmlSwitchEncoding(ctxt, XML_CHAR_ENCODING_UTF8);
}

/*
* Very first chars read from the document flow.
*/
Expand Down Expand Up @@ -6823,7 +6841,8 @@ htmlCtxtReadMemory(htmlParserCtxtPtr ctxt, const char *buffer, int size,

htmlCtxtReset(ctxt);

input = xmlParserInputBufferCreateMem(buffer, size, XML_CHAR_ENCODING_NONE);
input = xmlParserInputBufferCreateStatic(buffer, size,
XML_CHAR_ENCODING_NONE);
if (input == NULL) {
return(NULL);
}
Expand Down
11 changes: 10 additions & 1 deletion ExternData/Resources/C-Sources/libxml2/SAX2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1897,8 +1897,17 @@ xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt,
memset(ret, 0, sizeof(xmlAttr));
ret->type = XML_ATTRIBUTE_NODE;

/*
* xmlParseBalancedChunkMemoryRecover had a bug that could result in
* a mismatch between ctxt->node->doc and ctxt->myDoc. We use
* ctxt->node->doc here, but we should somehow make sure that the
* document pointers match.
*/

/* assert(ctxt->node->doc == ctxt->myDoc); */

ret->parent = ctxt->node;
ret->doc = ctxt->myDoc;
ret->doc = ctxt->node->doc;
ret->ns = namespace;

if (ctxt->dictNames)
Expand Down
4 changes: 2 additions & 2 deletions ExternData/Resources/C-Sources/libxml2/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,8 @@ static xmlMutex xmlRngMutex;
static unsigned globalRngState[2];

#ifdef XML_THREAD_LOCAL
XML_THREAD_LOCAL static int localRngInitialized = 0;
XML_THREAD_LOCAL static unsigned localRngState[2];
static XML_THREAD_LOCAL int localRngInitialized = 0;
static XML_THREAD_LOCAL unsigned localRngState[2];
#endif

ATTRIBUTE_NO_SANITIZE_INTEGER
Expand Down
25 changes: 21 additions & 4 deletions ExternData/Resources/C-Sources/libxml2/globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ XML_GLOBALS_ERROR
XML_GLOBALS_HTML
XML_GLOBALS_IO
XML_GLOBALS_PARSER
XML_GLOBALS_SAVE
XML_GLOBALS_TREE
#undef XML_OP
};
Expand All @@ -100,8 +99,14 @@ static xmlMutex xmlThrDefMutex;
* On Darwin, thread-local storage destructors seem to be run before
* pthread thread-specific data destructors. This causes ASan to
* report a use-after-free.
*
* On Windows, we can't use TLS in static builds. The RegisterWait
* callback would run after TLS was deallocated.
*/
#if defined(XML_THREAD_LOCAL) && !defined(__APPLE__)
#if defined(XML_THREAD_LOCAL) && \
!defined(__APPLE__) && \
(!defined(HAVE_WIN32_THREADS) || \
!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
#define USE_TLS
#endif

Expand All @@ -118,6 +123,13 @@ static XML_THREAD_LOCAL xmlGlobalState globalState;
defined(__GLIBC__) && \
__GLIBC__ * 100 + __GLIBC_MINOR__ < 234

#pragma weak pthread_getspecific
#pragma weak pthread_setspecific
#pragma weak pthread_key_create
#pragma weak pthread_key_delete
#pragma weak pthread_equal
#pragma weak pthread_self

#define XML_PTHREAD_WEAK

static int libxml_is_threaded = -1;
Expand Down Expand Up @@ -566,7 +578,13 @@ void xmlInitGlobalsInternal(void) {
(pthread_getspecific != NULL) &&
(pthread_setspecific != NULL) &&
(pthread_key_create != NULL) &&
(pthread_key_delete != NULL);
(pthread_key_delete != NULL) &&
/*
* pthread_equal can be inline, resuting in -Waddress warnings.
* Let's assume it's available if all the other functions are.
*/
/* (pthread_equal != NULL) && */
(pthread_self != NULL);
if (libxml_is_threaded == 0)
return;
#endif /* XML_PTHREAD_WEAK */
Expand Down Expand Up @@ -889,7 +907,6 @@ XML_GLOBALS_ERROR
XML_GLOBALS_HTML
XML_GLOBALS_IO
XML_GLOBALS_PARSER
XML_GLOBALS_SAVE
XML_GLOBALS_TREE
#undef XML_OP

Expand Down
76 changes: 64 additions & 12 deletions ExternData/Resources/C-Sources/libxml2/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,15 +913,42 @@ xmlHashScan(xmlHashTablePtr hash, xmlHashScanner scan, void *data) {
void
xmlHashScanFull(xmlHashTablePtr hash, xmlHashScannerFull scan, void *data) {
const xmlHashEntry *entry, *end;
xmlHashEntry old;
unsigned i;

if ((hash == NULL) || (hash->size == 0) || (scan == NULL))
return;

/*
* We must handle the case that a scanned entry is removed when executing
* the callback (xmlCleanSpecialAttr and possibly other places).
*
* Find the start of a probe sequence to avoid scanning entries twice if
* a deletion happens.
*/
entry = hash->table;
end = &hash->table[hash->size];
while (entry->hashValue != 0) {
if (++entry >= end)
entry = hash->table;
}

for (entry = hash->table; entry < end; entry++) {
if ((entry->hashValue != 0) && (entry->payload != NULL))
scan(entry->payload, data, entry->key, entry->key2, entry->key3);
for (i = 0; i < hash->size; i++) {
if ((entry->hashValue != 0) && (entry->payload != NULL)) {
/*
* Make sure to rescan after a possible deletion.
*/
do {
old = *entry;
scan(entry->payload, data, entry->key, entry->key2, entry->key3);
} while ((entry->hashValue != 0) &&
(entry->payload != NULL) &&
((entry->key != old.key) ||
(entry->key2 != old.key2) ||
(entry->key3 != old.key3)));
}
if (++entry >= end)
entry = hash->table;
}
}

Expand Down Expand Up @@ -966,22 +993,47 @@ xmlHashScanFull3(xmlHashTablePtr hash, const xmlChar *key,
const xmlChar *key2, const xmlChar *key3,
xmlHashScannerFull scan, void *data) {
const xmlHashEntry *entry, *end;
xmlHashEntry old;
unsigned i;

if ((hash == NULL) || (hash->size == 0) || (scan == NULL))
return;

/*
* We must handle the case that a scanned entry is removed when executing
* the callback (xmlCleanSpecialAttr and possibly other places).
*
* Find the start of a probe sequence to avoid scanning entries twice if
* a deletion happens.
*/
entry = hash->table;
end = &hash->table[hash->size];
while (entry->hashValue != 0) {
if (++entry >= end)
entry = hash->table;
}

for (entry = hash->table; entry < end; entry++) {
if (entry->hashValue == 0)
continue;
if (((key == NULL) ||
(strcmp((const char *) key, (const char *) entry->key) == 0)) &&
((key2 == NULL) || (xmlFastStrEqual(key2, entry->key2))) &&
((key3 == NULL) || (xmlFastStrEqual(key3, entry->key3))) &&
(entry->payload != NULL)) {
scan(entry->payload, data, entry->key, entry->key2, entry->key3);
for (i = 0; i < hash->size; i++) {
if ((entry->hashValue != 0) && (entry->payload != NULL)) {
/*
* Make sure to rescan after a possible deletion.
*/
do {
if (((key != NULL) && (strcmp((const char *) key,
(const char *) entry->key) != 0)) ||
((key2 != NULL) && (!xmlFastStrEqual(key2, entry->key2))) ||
((key3 != NULL) && (!xmlFastStrEqual(key3, entry->key3))))
break;
old = *entry;
scan(entry->payload, data, entry->key, entry->key2, entry->key3);
} while ((entry->hashValue != 0) &&
(entry->payload != NULL) &&
((entry->key != old.key) ||
(entry->key2 != old.key2) ||
(entry->key3 != old.key3)));
}
if (++entry >= end)
entry = hash->table;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#define __XML_ENTITIES_H__

#include <libxml/xmlversion.h>
#define XML_TREE_INTERNALS
#include <libxml/tree.h>
#undef XML_TREE_INTERNALS

#ifdef __cplusplus
extern "C" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ extern "C" {
typedef struct _xmlGlobalState xmlGlobalState;
typedef xmlGlobalState *xmlGlobalStatePtr;

XML_DEPRECATED XMLPUBFUN void
xmlInitGlobals(void);
XML_DEPRECATED XMLPUBFUN void
xmlCleanupGlobals(void);
XML_DEPRECATED XMLPUBFUN void
xmlInitializeGlobalState(xmlGlobalStatePtr gs);
XML_DEPRECATED XMLPUBFUN
Expand Down
44 changes: 43 additions & 1 deletion ExternData/Resources/C-Sources/libxml2/include/libxml/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#define __XML_PARSER_H__

#include <libxml/xmlversion.h>
#define XML_TREE_INTERNALS
#include <libxml/tree.h>
#undef XML_TREE_INTERNALS
#include <libxml/dict.h>
#include <libxml/hash.h>
#include <libxml/valid.h>
Expand Down Expand Up @@ -745,6 +747,19 @@ struct _xmlSAXHandler {
setDocumentLocatorSAXFunc setDocumentLocator;
startDocumentSAXFunc startDocument;
endDocumentSAXFunc endDocument;
/*
* `startElement` and `endElement` are only used by the legacy SAX1
* interface and should not be used in new software. If you really
* have to enable SAX1, the preferred way is set the `initialized`
* member to 1 instead of XML_SAX2_MAGIC.
*
* For backward compatibility, it's also possible to set the
* `startElementNs` and `endElementNs` handlers to NULL.
*
* You can also set the XML_PARSE_SAX1 parser option, but versions
* older than 2.12.0 will probably crash if this option is provided
* together with custom SAX callbacks.
*/
startElementSAXFunc startElement;
endElementSAXFunc endElement;
referenceSAXFunc reference;
Expand All @@ -758,8 +773,14 @@ struct _xmlSAXHandler {
getParameterEntitySAXFunc getParameterEntity;
cdataBlockSAXFunc cdataBlock;
externalSubsetSAXFunc externalSubset;
/*
* `initialized` should always be set to XML_SAX2_MAGIC to enable the
* modern SAX2 interface.
*/
unsigned int initialized;
/* The following fields are extensions available only on version 2 */
/*
* The following members are only used by the SAX2 interface.
*/
void *_private;
startElementNsSAX2Func startElementNs;
endElementNsSAX2Func endElementNs;
Expand Down Expand Up @@ -840,6 +861,15 @@ XMLPUBFUN const char *const *__xmlParserVersion(void);
XML_OP(xmlPedanticParserDefaultValue, int, XML_DEPRECATED) \
XML_OP(xmlSubstituteEntitiesDefaultValue, int, XML_DEPRECATED)

#ifdef LIBXML_OUTPUT_ENABLED
#define XML_GLOBALS_PARSER_OUTPUT \
XML_OP(xmlIndentTreeOutput, int, XML_NO_ATTR) \
XML_OP(xmlTreeIndentString, const char *, XML_NO_ATTR) \
XML_OP(xmlSaveNoEmptyTags, int, XML_NO_ATTR)
#else
#define XML_GLOBALS_PARSER_OUTPUT
#endif

#ifdef LIBXML_SAX1_ENABLED
#define XML_GLOBALS_PARSER_SAX1 \
XML_OP(xmlDefaultSAXHandler, xmlSAXHandlerV1, XML_DEPRECATED)
Expand All @@ -849,6 +879,7 @@ XMLPUBFUN const char *const *__xmlParserVersion(void);

#define XML_GLOBALS_PARSER \
XML_GLOBALS_PARSER_CORE \
XML_GLOBALS_PARSER_OUTPUT \
XML_GLOBALS_PARSER_SAX1

#define XML_OP XML_DECLARE_GLOBAL
Expand All @@ -872,6 +903,11 @@ XML_GLOBALS_PARSER
XML_GLOBAL_MACRO(xmlPedanticParserDefaultValue)
#define xmlSubstituteEntitiesDefaultValue \
XML_GLOBAL_MACRO(xmlSubstituteEntitiesDefaultValue)
#ifdef LIBXML_OUTPUT_ENABLED
#define xmlIndentTreeOutput XML_GLOBAL_MACRO(xmlIndentTreeOutput)
#define xmlTreeIndentString XML_GLOBAL_MACRO(xmlTreeIndentString)
#define xmlSaveNoEmptyTags XML_GLOBAL_MACRO(xmlSaveNoEmptyTags)
#endif
#endif
/** DOC_ENABLE */

Expand All @@ -882,6 +918,12 @@ XMLPUBFUN void
xmlInitParser (void);
XMLPUBFUN void
xmlCleanupParser (void);
XML_DEPRECATED
XMLPUBFUN void
xmlInitGlobals (void);
XML_DEPRECATED
XMLPUBFUN void
xmlCleanupGlobals (void);

/*
* Input functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <libxml/xmlversion.h>
#include <libxml/xmlerror.h>
#include <libxml/xmlstring.h>
#include <libxml/tree.h>

#ifdef LIBXML_SCHEMAS_ENABLED

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <libxml/xmlregexp.h>
#include <libxml/hash.h>
#include <libxml/dict.h>
#include <libxml/tree.h>

#ifdef __cplusplus
extern "C" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#ifdef LIBXML_SCHEMATRON_ENABLED

#include <libxml/xmlerror.h>
#include <libxml/tree.h>

#ifdef __cplusplus
Expand Down
Loading

0 comments on commit defc777

Please sign in to comment.