Skip to content

Commit 525b398

Browse files
committed
[io] use safer overload of TKey::ReadKeyBuffer() in TFile::Recover()
This prevents potential oob stack reads in case of corrupted TFiles
1 parent 649f1ab commit 525b398

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

io/io/src/TFile.cxx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,8 +1396,8 @@ TFile::InfoListRet TFile::GetStreamerInfoListImpl(bool lookupSICache)
13961396
if (fSeekInfo) {
13971397
TDirectory::TContext ctxt(this); // gFile and gDirectory used in ReadObj
13981398
auto key = std::make_unique<TKey>(this);
1399-
std::vector<char> buffer(fNbytesInfo+1);
1400-
auto buf = buffer.data();
1399+
auto buffer = std::make_unique<char[]>(fNbytesInfo+1);
1400+
auto buf = buffer.get();
14011401
Seek(fSeekInfo); // NOLINT: silence clang-tidy warnings
14021402
if (ReadBuffer(buf,fNbytesInfo)) { // NOLINT: silence clang-tidy warnings
14031403
// ReadBuffer returns kTRUE in case of failure.
@@ -1419,8 +1419,9 @@ TFile::InfoListRet TFile::GetStreamerInfoListImpl(bool lookupSICache)
14191419
return {nullptr, 0, hash};
14201420
}
14211421
}
1422-
key->ReadKeyBuffer(buf);
1423-
list = dynamic_cast<TList*>(key->ReadObjWithBuffer(buffer.data()));
1422+
if (!key->ReadKeyBuffer(buf, fNbytesInfo))
1423+
return {nullptr, 1, hash};
1424+
list = dynamic_cast<TList*>(key->ReadObjWithBuffer(buffer.get()));
14241425
if (list) list->SetOwner();
14251426
} else {
14261427
list = (TList*)Get("StreamerInfo"); //for versions 2.26 (never released)
@@ -2171,8 +2172,9 @@ Int_t TFile::Recover()
21712172
if (seekpdir == fSeekDir && tclass && !tclass->InheritsFrom(TFile::Class())
21722173
&& strcmp(classname,"TBasket")) {
21732174
TKey *key = new TKey(this);
2174-
key->ReadKeyBuffer(bufread);
2175-
if (!strcmp(key->GetName(),"StreamerInfo")) {
2175+
char *bufread = header;
2176+
bool keyRead = key->ReadKeyBuffer(bufread, sizeof(header));
2177+
if (!keyRead || !strcmp(key->GetName(), "StreamerInfo")) {
21762178
fSeekInfo = seekkey;
21772179
SafeDelete(fInfoCache);
21782180
fNbytesInfo = nbytes;

0 commit comments

Comments
 (0)