An XMPFile kept its path, open flags and pending packet in writable,
configurable properties, so a script could assign a packet to a file
opened for reading and closeFile wrote it without checking the update
flag or reading the packet.
- The properties holding an XMPFile's state are not writable,
enumerable or configurable, and the pending packet is one of them from
the start.
- The XMPMeta docs say that only the namespaces a packet's names use
are registered, which is what reading a packet does.
Test: a_script_cannot_change_the_state_of_an_xmp_file in
crates/engine/src/tests/script_xmp.rs. Docs: docs/mcp.md.
setProperty and the other property members took a path in the RDF or
XML namespace, and serialize() wrote a packet that XMPMeta could not
read back. Such a path now throws "... is not a valid property name".
Test: rdf_and_xml_namespaces_hold_no_properties in
crates/js/src/xmp_tests.rs.
closeFile() writes a sidecar through a new temporary file and renames it
over the sidecar, so a 0600 sidecar became 0644 under a 022 umask. The
temporary file now takes the sidecar's permission bits before the
rename, as File.copy does for its target.
Test: a_replaced_sidecar_keeps_its_permissions (Unix only) in
crates/engine/src/tests/script_xmp.rs.
A property holding text next to its rdf:Bag, rdf:Seq or rdf:Alt was
read as an array of simple items, and serialize() dropped the text.
Such a property is now kept as the XML it was written in.
Test: text_beside_an_array_is_kept in crates/js/src/xmp_tests.rs.
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.
A namespace declared only inside a structure, an array of structures or
on a qualifier was not registered when the packet was read, so
XMPMeta.getNamespacePrefix gave undefined for it. Reading a value that
is kept as it was written now registers the namespaces its element and
attribute names use, other than RDF and XML.
Test: namespaces_inside_kept_values_are_registered in
crates/js/src/xmp_tests.rs.
- setLocalizedText reads its generic language argument. With no item in
the specific language and exactly one item in the generic language
or a variant of it, that item changes, as the XMP Toolkit SDK's
SetLocalizedText does (XMPCore/source/XMPMeta-GetSet.cpp); with
several, the specific language is added.
- A packet read from rdf:RDF alone could hold a value nested 64
elements deep that serialize() then wrote under x:xmpmeta, 65 deep,
so the written packet did not read back. A value is now measured as
deep as serialize() writes it, and one past 64 elements throws when
the packet is read.
Tests: localized_text_updates_a_single_generic_language_item and
deeply_nested_values_read_back_after_serializing in
crates/js/src/xmp_tests.rs. Docs: docs/mcp.md.
XMPMeta.registerNamespace and packets that declare namespaces could add
up to 4,096 namespaces of any length, held outside the script heap.
- A namespace URI over 1,024 bytes and a prefix over 128 bytes, the
`_n_` suffix included, throw "the XMP data is too large".
- The registered namespaces hold at most 1 MiB together; a namespace
past that throws the same error and is not registered.
- Reading a packet takes fuel for the namespaces it copies.
- Error messages hold at most the first 200 characters of a name,
path, value or namespace the script gave.
Tests: namespace_lengths_and_the_registry_budget_are_bounded,
long_namespaces_from_scripts_and_packets_are_refused and
error_messages_hold_a_bounded_part_of_the_script_text in
crates/js/src/xmp_tests.rs. Docs: docs/mcp.md.
new ExternalObject("lib:AdobeXMPScript") defines XMPMeta, XMPFile and
XMPConst in the script engine; any other library name throws and no
native library is loaded.
- XMPMeta reads a packet string and serializes one, with or without the
packet wrapper: simple properties, arrays of simple items, language
alternatives and namespace registration and lookup. Structures and
values with qualifiers are kept as they were written.
- XMPFile reads and writes only where File may. A .xmp sidecar opened
for update takes putXMP, and closeFile writes it through a temporary
file in the same folder when the script may write there; other files
are scanned for their packet and are read only. File's 8 MiB limit
applies before reading.
- Packets are parsed with craft-xml: a document type declaration, an
undefined entity, nesting over 64 levels and a packet over 8 MiB are
refused with an error.
- Members not built yet (iterators, structure fields, qualifiers,
aliases, sorting, byte-array packets, XMPFile.getFormatInfo) throw
that they are not available yet.
The XMPConst flag values follow the public XMP Toolkit SDK header
XMP_Const.h. Tests: crates/js/src/xmp_tests.rs, with fuzz cases for the
packet parser and scanner, and crates/engine/src/tests/script_xmp.rs.
Docs: docs/mcp.md and docs/target-app-parity.md.