[xml/sgml-pkgs] Bug#1111803: libxml2: xmllint with both --valid and --relaxng yields "Relax-NG validity error : ID ... redefined" errors
Vincent Lefevre
vincent at vinc17.net
Sat Aug 23 18:00:17 BST 2025
Control: tags -1 fixed-upstream patch
On 2025-08-22 19:34:54 +0200, Vincent Lefevre wrote:
> I can reproduce the bug under Termux/Android, and I've reported
> the bug upstream, with a simple testcase.
The upstream patch against the 2.14 branch[*] (attached) fixes
this bug, for both my simple testcase and my actual files.
[*] https://gitlab.gnome.org/GNOME/libxml2/-/commit/1172b777fae798e2aacac028963bc31353af1ebc
--
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)
-------------- next part --------------
>From 1172b777fae798e2aacac028963bc31353af1ebc Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer <wellnhofer at aevum.de>
Date: Sat, 23 Aug 2025 14:59:50 +0200
Subject: [PATCH] valid: Don't add ids when validating entity content
The id table shouldn't reference ids in entities. The id will be created
when expanding the entity.
Probably regressed with d025cfbb.
Note that we still register ids in entities if entities are not
replaced. This is required to make IDREF checks work.
Fixes #974.
---
SAX2.c | 22 ++++++++++++++++++++++
include/private/parser.h | 4 ++++
valid.c | 3 ++-
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/SAX2.c b/SAX2.c
index b5c2e4760..0f54b7f50 100644
--- a/SAX2.c
+++ b/SAX2.c
@@ -1184,8 +1184,19 @@ xmlSAX1Attribute(xmlParserCtxtPtr ctxt, const xmlChar *fullname,
xmlFree(val);
}
} else {
+ /*
+ * When replacing entities, make sure that IDs in
+ * entities aren't registered. This also shouldn't be
+ * done when entities aren't replaced, but this would
+ * require to rework IDREF checks.
+ */
+ if (ctxt->input->entity != NULL)
+ ctxt->vctxt.flags |= XML_VCTXT_IN_ENTITY;
+
ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt, ctxt->myDoc,
ctxt->node, ret, value);
+
+ ctxt->vctxt.flags &= ~XML_VCTXT_IN_ENTITY;
}
} else
#endif /* LIBXML_VALID_ENABLED */
@@ -2052,8 +2063,19 @@ xmlSAX2AttributeNs(xmlParserCtxtPtr ctxt,
if (dup == NULL)
xmlSAX2ErrMemory(ctxt);
+ /*
+ * When replacing entities, make sure that IDs in
+ * entities aren't registered. This also shouldn't be
+ * done when entities aren't replaced, but this would
+ * require to rework IDREF checks.
+ */
+ if (ctxt->input->entity != NULL)
+ ctxt->vctxt.flags |= XML_VCTXT_IN_ENTITY;
+
ctxt->valid &= xmlValidateOneAttribute(&ctxt->vctxt,
ctxt->myDoc, ctxt->node, ret, dup);
+
+ ctxt->vctxt.flags &= ~XML_VCTXT_IN_ENTITY;
}
} else
#endif /* LIBXML_VALID_ENABLED */
diff --git a/include/private/parser.h b/include/private/parser.h
index d5f2fef98..3e7fa59a9 100644
--- a/include/private/parser.h
+++ b/include/private/parser.h
@@ -20,6 +20,10 @@
* Set if the validation context is part of a parser context.
*/
#define XML_VCTXT_USE_PCTXT (1u << 1)
+/**
+ * Set when parsing entities.
+ */
+#define XML_VCTXT_IN_ENTITY (1u << 3)
/*
* TODO: Rename to avoid confusion with xmlParserInputFlags
diff --git a/valid.c b/valid.c
index 63535270e..2e379997a 100644
--- a/valid.c
+++ b/valid.c
@@ -4313,7 +4313,8 @@ xmlValidateOneAttribute(xmlValidCtxtPtr ctxt, xmlDocPtr doc,
}
/* Validity Constraint: ID uniqueness */
- if (attrDecl->atype == XML_ATTRIBUTE_ID) {
+ if (attrDecl->atype == XML_ATTRIBUTE_ID &&
+ (ctxt->flags & XML_VCTXT_IN_ENTITY) == 0) {
if (xmlAddID(ctxt, doc, value, attr) == NULL)
ret = 0;
}
--
GitLab
More information about the debian-xml-sgml-pkgs
mailing list