mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Scripts: an undeclared prefix inside a kept XMP value is malformed
A structure or qualifier whose element or attribute used a prefix that nothing declared was read and then serialized with the prefix unbound. Such a packet is now refused as not well-formed XMP. Test: namespaces_inside_kept_values_are_registered in crates/js/src/xmp_tests.rs.
This commit is contained in:
1 parent
cac32433a9
commit
b8bf41b7a9
3 files changed
+10
-2
No files matched your search
@@ -543,11 +543,12 @@ fn read_property(p: &El, scope: &mut Scope, registry: &mut Registry) -> Result<P
|
||||
}
|
||||
|
||||
/// Registers the namespaces of the name and the attributes of `el`, with `scope` holding the
|
||||
/// bindings in scope there, other than RDF, XML and no namespace.
|
||||
/// bindings in scope there, other than RDF, XML and no namespace. A prefix nothing declares makes
|
||||
/// the packet malformed.
|
||||
fn register_names(el: &El, scope: &Scope, registry: &mut Registry) -> Result<(), XmpError> {
|
||||
let names = std::iter::once((el.name.as_str(), true)).chain(attrs(el).into_iter().map(|(k, _)| (k, false)));
|
||||
for (name, element) in names {
|
||||
let Some((ns, _)) = resolve(name, scope, element) else { continue };
|
||||
let (ns, _) = resolve(name, scope, element).ok_or(XmpError::Malformed)?;
|
||||
if !ns.is_empty() && ns != RDF && ns != XML {
|
||||
registry.register(&ns, name.split_once(':').map_or("ns", |(p, _)| p))?;
|
||||
}
|
||||
|
||||
@@ -944,6 +944,7 @@ fn file_ctor(i: &mut Interp, _: Value, args: &[Value], _: bool) -> JsResult<Valu
|
||||
return Err(not_handled(i, what, &format!("0x{format:08X}")));
|
||||
}
|
||||
let open_flags = flags(i, &arg(args, 2), what)?;
|
||||
// `OPEN_ONLY_XMP` asks for the XMP alone, which is all an `XMPFile` reads.
|
||||
only(i, open_flags, OPEN_FOR_READ | OPEN_FOR_UPDATE | OPEN_ONLY_XMP | OPEN_USE_PACKET_SCANNING, what)?;
|
||||
let update = open_flags & OPEN_FOR_UPDATE != 0;
|
||||
let scan = open_flags & OPEN_USE_PACKET_SCANNING != 0;
|
||||
|
||||
@@ -360,6 +360,12 @@ fn namespaces_inside_kept_values_are_registered() {
|
||||
let src =
|
||||
format!("var m = new XMPMeta({packet:?}); [XMPMeta.getNamespacePrefix('http://inner/'), XMPMeta.getNamespacePrefix('http://q/')].join('|')");
|
||||
assert_eq!(string(&src), "in:|q:");
|
||||
for value in ["<a:p><bad:c>1</bad:c></a:p>", "<a:p bad:k='v'>x</a:p>"] {
|
||||
let packet = format!(
|
||||
"<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'><rdf:Description xmlns:a='http://a/'>{value}</rdf:Description></rdf:RDF>"
|
||||
);
|
||||
assert_eq!(xmp::parse(&packet, &mut Registry::default()), Err(XmpError::Malformed), "an undeclared prefix in {value}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user