From 71e9bdd4e4362d27be188effc78b0b722f2dda11 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Wed, 13 Mar 2024 16:57:49 -0400 Subject: [PATCH] validate the value of the `index` attribute --- .../c++/six.sidd/source/DerivedXMLParser300.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/six/modules/c++/six.sidd/source/DerivedXMLParser300.cpp b/six/modules/c++/six.sidd/source/DerivedXMLParser300.cpp index 782e6c151..e652c974c 100644 --- a/six/modules/c++/six.sidd/source/DerivedXMLParser300.cpp +++ b/six/modules/c++/six.sidd/source/DerivedXMLParser300.cpp @@ -335,6 +335,18 @@ void DerivedXMLParser300::parseJ2KCompression(const xml::lite::Element& j2kElem, for (size_t ii = 0; ii < layerElems.size(); ++ii) { + // In SIDD 3.0, the `index` attribute type changed from `positiveInteger` to `nonNegativeInteger` + // (matching C-style indexing). Since we had a problem with this, use the opportunity to + // validate the `index` value. + const auto& attributes = layerElems[ii]->getAttributes(); + std::string strIndex; + if (attributes.getValue("index", strIndex)) + { + // The schema says this is required, but we might not be validating. + const size_t index = std::stoi(strIndex); + assert(ii == index); // again, we might not be validating the XML + } + parseDouble(getFirstAndOnly(layerElems[ii], "Bitrate"), j2k.layerInfo[ii].bitRate); } }