Skip to content

Commit 42e1212

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 8693edf commit 42e1212

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
@@ -1404,8 +1404,8 @@ TFile::InfoListRet TFile::GetStreamerInfoListImpl(bool lookupSICache)
14041404
if (fSeekInfo) {
14051405
TDirectory::TContext ctxt(this); // gFile and gDirectory used in ReadObj
14061406
auto key = std::make_unique<TKey>(this);
1407-
std::vector<char> buffer(fNbytesInfo+1);
1408-
auto buf = buffer.data();
1407+
auto buffer = std::make_unique<char[]>(fNbytesInfo+1);
1408+
auto buf = buffer.get();
14091409
Seek(fSeekInfo); // NOLINT: silence clang-tidy warnings
14101410
if (ReadBuffer(buf,fNbytesInfo)) { // NOLINT: silence clang-tidy warnings
14111411
// ReadBuffer returns kTRUE in case of failure.
@@ -1427,8 +1427,9 @@ TFile::InfoListRet TFile::GetStreamerInfoListImpl(bool lookupSICache)
14271427
return {nullptr, 0, hash};
14281428
}
14291429
}
1430-
key->ReadKeyBuffer(buf);
1431-
list = dynamic_cast<TList*>(key->ReadObjWithBuffer(buffer.data()));
1430+
if (!key->ReadKeyBuffer(buf, fNbytesInfo))
1431+
return {nullptr, 1, hash};
1432+
list = dynamic_cast<TList*>(key->ReadObjWithBuffer(buffer.get()));
14321433
if (list) list->SetOwner();
14331434
} else {
14341435
list = (TList*)Get("StreamerInfo"); //for versions 2.26 (never released)
@@ -2179,8 +2180,9 @@ Int_t TFile::Recover()
21792180
if (seekpdir == fSeekDir && tclass && !tclass->InheritsFrom(TFile::Class())
21802181
&& strcmp(classname,"TBasket")) {
21812182
TKey *key = new TKey(this);
2182-
key->ReadKeyBuffer(bufread);
2183-
if (!strcmp(key->GetName(),"StreamerInfo")) {
2183+
char *bufread = header;
2184+
bool keyRead = key->ReadKeyBuffer(bufread, sizeof(header));
2185+
if (!keyRead || !strcmp(key->GetName(), "StreamerInfo")) {
21842186
fSeekInfo = seekkey;
21852187
SafeDelete(fInfoCache);
21862188
fNbytesInfo = nbytes;

0 commit comments

Comments
 (0)