Skip to content

Commit e87b145

Browse files
jblomerdpiparo
authored andcommitted
[ntuple] prevent accidental treatment of unsupported stdlib collections
1 parent 156972f commit e87b145

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

tree/ntuple/src/RFieldMeta.cxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,20 @@ ROOT::RProxiedCollectionField::RProxiedCollectionField(std::string_view fieldNam
745745
{
746746
if (!classp->GetCollectionProxy())
747747
throw RException(R__FAIL(std::string(GetTypeName()) + " has no associated collection proxy"));
748+
if (classp->Property() & kIsDefinedInStd) {
749+
static const std::vector<std::string> supportedStdTypes = {
750+
"std::set<", "std::unordered_set<", "std::multiset<", "std::unordered_multiset<",
751+
"std::map<", "std::unordered_map<", "std::multimap<", "std::unordered_multimap<"};
752+
bool isSupported = false;
753+
for (const auto &tn : supportedStdTypes) {
754+
if (GetTypeName().rfind(tn, 0) == 0) {
755+
isSupported = true;
756+
break;
757+
}
758+
}
759+
if (!isSupported)
760+
throw RException(R__FAIL(std::string(GetTypeName()) + " is not supported"));
761+
}
748762

749763
fProxy.reset(classp->GetCollectionProxy()->Generate());
750764
fProperties = fProxy->GetProperties();

tree/ntuple/test/ntuple_types.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,6 +2056,9 @@ TEST(RNTuple, TClassStlDerived)
20562056

20572057
TEST(RNTuple, TVirtualCollectionProxy)
20582058
{
2059+
// Unsupported stdlib collections should throw
2060+
EXPECT_THROW(ROOT::RFieldBase::Create("l", "std::list<int>").Unwrap(), ROOT::RException);
2061+
20592062
SimpleCollectionProxy<StructUsingCollectionProxy<char>> proxyC;
20602063
// Exposing as a non-vector forces iteration over collection elements in `ReadGlobalImpl()`
20612064
SimpleCollectionProxy<StructUsingCollectionProxy<float>, ROOT::kSTLdeque> proxyF;

0 commit comments

Comments
 (0)