Check for correctly sized propertylists to avoid dropping molecules (#8921)

* Fixes #8918

* Use only the one check for compatible sizes

---------

Co-authored-by: Brian Kelley <bkelley@glysade.com>
This commit is contained in:
Brian Kelley
2026-01-08 00:08:54 -05:00
committed by GitHub
parent cef43e8aef
commit 9558cb8114
2 changed files with 13 additions and 6 deletions

View File

@@ -12,6 +12,7 @@
#define RD_FILEPARSERUTILS_H
#include <string>
#include <iostream>
#include <RDGeneral/BoostStartInclude.h>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
@@ -119,12 +120,6 @@ void applyMolListProp(ROMol &mol, const std::string &pn,
std::vector<std::string> tokens;
boost::split(tokens, strVect, boost::is_any_of(" \t\n"),
boost::token_compress_on);
if (tokens.size() < nItems) {
BOOST_LOG(rdWarningLog) << "Property list " << pn << " too short, only "
<< tokens.size() << " elements found; expecting "
<< nItems << ". Ignoring it." << std::endl;
return;
}
std::string mv = missingValueMarker;
size_t first_token = 0;
if (tokens.size() == nItems + 1 && tokens[0].front() == '[' &&
@@ -136,6 +131,12 @@ void applyMolListProp(ROMol &mol, const std::string &pn,
BOOST_LOG(rdWarningLog) << "Missing value marker for property " << pn
<< " is empty." << std::endl;
}
if(tokens.size() - first_token != nItems) {
BOOST_LOG(rdWarningLog) << "Property list " << pn << " has incompatible size, "
<< tokens.size() << " elements found; expecting "
<< nItems << ". Ignoring it." << std::endl;
return;
}
for (size_t i = first_token; i < tokens.size(); ++i) {
if (tokens[i] != mv) {
unsigned int itemid = i - first_token;

View File

@@ -188,6 +188,9 @@ one n/a three
> <bond.prop.foo> (1)
bar baz blah
> <atom.iprop.TooLong> (1)
0 1 2 3 4
$$$$
)SDF";
SECTION("no processing") {
@@ -210,6 +213,9 @@ $$$$
std::string val;
CHECK(m->getBondWithIdx(0)->getPropIfPresent("foo", val));
CHECK(val == "bar");
CHECK(m->hasProp("atom.iprop.TooLong"));
CHECK(!m->getAtomWithIdx(0)->hasProp("TooLong"));
}
}