Files
firefox/parser/expat/08_include_xmlns.patch
Andrew McCreight 6f88edd50e Bug 1988534, part 3 - Fix Firefox patches for Expat. r=hsivonen
* Mostly, this unbitrots the patches and updates line numbers.

* Define MOZ_XML_GetMismatchedTag and MOZ_XML_ProcessingEntityValue in
  moz_xmlparse.c instead of these patches, to reduce future bitrot. This means
  that 06_report_processing_entity.patch can be removed entirely.

* For 06_always_store_rawnames.patch, in the section from line 33 to 71 nothing
  is really changing. The old diff was just really awful for some reason. For
  the final chunk from line 72 to 86, that chunk of code with a call to
  storeRawNames in internalEntityProcessor, so it could be deleted.

* 11_nested_entities.patch handles some kind of issue with nested entities.
  This seems to correspond to code in internalEntityProcessor where there
  is now an assertion:
    assert(parser->m_openInternalEntities == openEntity);
  So I guess it is no longer needed. Peter removed it from his patch stack.

* Renumber the patches to account for the two removed ones.

* In 11_no_debug_report.patch, a new struct MALLOC_TRACKER has been added.
  I had to remove new debugLevel here, as well as peakBytesAllocated, which
  as it says is only used when debugLevel is set. expat_heap_stat is also
  only used by that code, so it gets removed, too.

* 12_unused.patch removes a bunch of unused code. The stuff around line 56
  had to change because a new function, parserBusy, that is used was added
  into the middle of a bunch of unused functions.

Differential Revision: https://phabricator.services.mozilla.com/D278892
2026-01-15 20:59:58 +00:00

141 lines
5.4 KiB
Diff

diff --git a/expat/lib/xmlparse.c b/expat/lib/xmlparse.c
--- a/expat/lib/xmlparse.c
+++ b/expat/lib/xmlparse.c
@@ -3929,6 +3929,9 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr,
int n;
XML_Char *uri;
int nPrefixes = 0;
+/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */
+ int nXMLNSDeclarations = 0;
+/* END MOZILLA CHANGE */
BINDING *binding;
const XML_Char *localPart;
@@ -4086,7 +4089,15 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr,
appAtts[attIndex], bindingsPtr);
if (result)
return result;
+/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */
+#if 0
--attIndex;
+#else
+ attIndex++;
+ nXMLNSDeclarations++;
+ (attId->name)[-1] = 3;
+#endif
+/* END MOZILLA CHANGE */
} else {
/* deal with other prefixed names later */
attIndex++;
@@ -4118,6 +4129,12 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr,
da->value, bindingsPtr);
if (result)
return result;
+/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */
+ (da->id->name)[-1] = 3;
+ nXMLNSDeclarations++;
+ appAtts[attIndex++] = da->id->name;
+ appAtts[attIndex++] = da->value;
+/* END MOZILLA CHANGE */
} else {
(da->id->name)[-1] = 2;
nPrefixes++;
@@ -4136,7 +4153,13 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr,
/* expand prefixed attribute names, check for duplicates,
and clear flags that say whether attributes were specified */
i = 0;
+/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */
+#if 0
if (nPrefixes) {
+#else
+ if (nPrefixes || nXMLNSDeclarations) {
+#endif
+/* END MOZILLA CHANGE */
unsigned int j; /* hash table index */
unsigned long version = parser->m_nsAttsVersion;
@@ -4146,6 +4169,9 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr,
}
unsigned int nsAttsSize = 1u << parser->m_nsAttsPower;
+/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */
+ if (nPrefixes) {
+/* END MOZILLA CHANGE */
unsigned char oldNsAttsPower = parser->m_nsAttsPower;
/* size of hash table must be at least 2 * (# of prefixed attributes) */
if ((nPrefixes << 1)
@@ -4194,6 +4220,9 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr,
parser->m_nsAtts[--j].version = version;
}
parser->m_nsAttsVersion = --version;
+/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */
+ }
+/* END MOZILLA CHANGE */
/* expand prefixed names and check for duplicates */
for (; i < attIndex; i += 2) {
@@ -4293,10 +4322,63 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr,
parser->m_nsAtts[j].hash = uriHash;
parser->m_nsAtts[j].uriName = s;
+/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */
+#if 0
if (! --nPrefixes) {
+#else
+ if (! --nPrefixes && ! nXMLNSDeclarations) {
+#endif
+/* END MOZILLA CHANGE */
i += 2;
break;
}
+/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */
+ } else if (s[-1] == 3) { /* xmlns attribute */
+ static const XML_Char xmlnsNamespace[] = {
+ ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH,
+ ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, ASCII_3, ASCII_PERIOD,
+ ASCII_o, ASCII_r, ASCII_g, ASCII_SLASH, ASCII_2, ASCII_0, ASCII_0, ASCII_0,
+ ASCII_SLASH, ASCII_x, ASCII_m, ASCII_l, ASCII_n, ASCII_s, ASCII_SLASH, '\0'
+ };
+ static const XML_Char xmlnsPrefix[] = {
+ ASCII_x, ASCII_m, ASCII_l, ASCII_n, ASCII_s, '\0'
+ };
+
+ ((XML_Char *)s)[-1] = 0; /* clear flag */
+ if (! poolAppendString(&parser->m_tempPool, xmlnsNamespace)
+ || ! poolAppendChar(&parser->m_tempPool, parser->m_namespaceSeparator))
+ return XML_ERROR_NO_MEMORY;
+ s += sizeof(xmlnsPrefix) / sizeof(xmlnsPrefix[0]) - 1;
+ if (*s == XML_T(':')) {
+ ++s;
+ do { /* copies null terminator */
+ if (! poolAppendChar(&parser->m_tempPool, *s))
+ return XML_ERROR_NO_MEMORY;
+ } while (*s++);
+ if (parser->m_ns_triplets) { /* append namespace separator and prefix */
+ parser->m_tempPool.ptr[-1] = parser->m_namespaceSeparator;
+ if (! poolAppendString(&parser->m_tempPool, xmlnsPrefix)
+ || ! poolAppendChar(&parser->m_tempPool, '\0'))
+ return XML_ERROR_NO_MEMORY;
+ }
+ }
+ else {
+ /* xlmns attribute without a prefix. */
+ if (! poolAppendString(&parser->m_tempPool, xmlnsPrefix)
+ || ! poolAppendChar(&parser->m_tempPool, '\0'))
+ return XML_ERROR_NO_MEMORY;
+ }
+
+ /* store expanded name in attribute list */
+ s = poolStart(&parser->m_tempPool);
+ poolFinish(&parser->m_tempPool);
+ appAtts[i] = s;
+
+ if (! --nXMLNSDeclarations && ! nPrefixes) {
+ i += 2;
+ break;
+ }
+/* END MOZILLA CHANGE */
} else /* not prefixed */
((XML_Char *)s)[-1] = 0; /* clear flag */
}