diff --git a/Code/GraphMol/FileParsers/MolFileParser.cpp b/Code/GraphMol/FileParsers/MolFileParser.cpp index 208035f96..e58aa779b 100644 --- a/Code/GraphMol/FileParsers/MolFileParser.cpp +++ b/Code/GraphMol/FileParsers/MolFileParser.cpp @@ -151,6 +151,17 @@ std::string getV3000Line(std::istream *inStream, unsigned int &line) { ++line; auto inl = getLine(inStream); std::string_view tempStr = inl; + + // Reject any non-ascii characters. + if (std::any_of(tempStr.begin(), tempStr.end(), [](char c) { + return static_cast(c) > 127; + })) { + std::ostringstream errout; + errout << "Invalid character found in data stream when parsing V3000 line: " + << tempStr; + throw MolFileUnhandledFeatureException(errout.str()); + } + if (tempStr.size() < 7 || tempStr.substr(0, 7) != "M V30 ") { std::ostringstream errout; errout << "Line " << line << " does not start with 'M V30 '" << std::endl; diff --git a/Code/GraphMol/FileParsers/MolSGroupParsing.cpp b/Code/GraphMol/FileParsers/MolSGroupParsing.cpp index f02366f22..330387b45 100644 --- a/Code/GraphMol/FileParsers/MolSGroupParsing.cpp +++ b/Code/GraphMol/FileParsers/MolSGroupParsing.cpp @@ -1132,7 +1132,17 @@ void ParseV3000ParseLabel(const std::string &label, } else if (label == "PARENT") { // Store relationship until all SGroups have been read unsigned int parentIdx; + if (lineStream.eof()) { + std::ostringstream errout; + errout << "PARENT label not found on line " << line; + throw FileParseException(errout.str()); + } lineStream >> parentIdx; + if (lineStream.fail()) { + std::ostringstream errout; + errout << "Invalid PARENT label found on line " << line; + throw FileParseException(errout.str()); + } sgroup.setProp("PARENT", parentIdx); } else if (label == "COMPNO") { unsigned int compno; diff --git a/Code/GraphMol/SmilesParse/CXSmilesOps.cpp b/Code/GraphMol/SmilesParse/CXSmilesOps.cpp index ee58181a9..e7ef6f6d9 100644 --- a/Code/GraphMol/SmilesParse/CXSmilesOps.cpp +++ b/Code/GraphMol/SmilesParse/CXSmilesOps.cpp @@ -736,6 +736,10 @@ bool parse_data_sgroup(Iterator &first, Iterator last, RDKit::RWMol &mol, } ++first; + if (first >= last) { + return false; + } + parse_data_sgroup_attr(first, last, sgroup, keepSGroup, "FIELDNAME"); // FIX: @@ -743,12 +747,24 @@ bool parse_data_sgroup(Iterator &first, Iterator last, RDKit::RWMol &mol, sgroup.setProp("FIELDDISP", " 0.0000 0.0000 DR ALL 0 0"); } + if (first >= last) { + return false; + } parse_data_sgroup_attr(first, last, sgroup, keepSGroup, "DATAFIELDS", true); + if (first >= last) { + return false; + } parse_data_sgroup_attr(first, last, sgroup, keepSGroup, "QUERYOP"); + if (first >= last) { + return false; + } parse_data_sgroup_attr(first, last, sgroup, keepSGroup, "FIELDINFO"); + if (first >= last) { + return false; + } parse_data_sgroup_attr(first, last, sgroup, keepSGroup, "FIELDTAG"); if (first < last && *first == '(') {