-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[tree] In TBasket/TBranch, error out if reading oob in the streamer #22165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1005,16 +1005,44 @@ void TBasket::Streamer(TBuffer &b) | |
| flag -= 80; | ||
| } | ||
| if (!mustGenerateOffsets && flag && (flag % 10 != 2)) { | ||
| // NOTE: fNevBuf is the number of entries stored in the basket, while fNevBufSize is the capacity of the | ||
| // fEntryOffset and fDisplacement arrays. | ||
| if (fNevBuf > fNevBufSize) { | ||
| Error( | ||
| "Streamer", | ||
| "Inconsistent length for the entry offset buffer (%d events for a buffer size of %d). Refusing to deserialize.", | ||
| fNevBuf, fNevBufSize); | ||
| MakeZombie(); | ||
| return; | ||
| } | ||
| ResetEntryOffset(); | ||
| fEntryOffset = new Int_t[fNevBufSize]; | ||
| if (fNevBuf) b.ReadArray(fEntryOffset); | ||
| if (fNevBuf) { | ||
| // Alas, ReadArray will read the number of elements to store into fEntryOffset from the file, but it | ||
| // has no way of knowing whether we're passing a large-enough array. | ||
| // Therefore we prevent the problem altogether by ignoring fNevBufSize and just having ReadArray allocate | ||
| // the buffer for us. This way we are sure that it will be of the correct size even if the file contains | ||
| // corrupted data. | ||
|
Comment on lines
+1023
to
+1024
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find that we can do better. With this change we swap the potential problem that the actual number of elements read is larger than the allocated memory (leading to out of bound writes) for the potential problem that the actual number of elements read is smaller than the expected number of elements (leading to out of bounds reads). Maybe a better way is to explicitly read the size and to use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I decided to use the returned (actual) |
||
| fEntryOffset = nullptr; | ||
| auto nElemsRead = b.ReadArray(fEntryOffset); | ||
| if (nElemsRead != fNevBufSize) { | ||
| Error( | ||
| "Streamer", | ||
| "Inconsistent length for the entry offset buffer (expected %d elements, read %d). Refusing to deserialize.", | ||
| fNevBufSize, nElemsRead); | ||
| MakeZombie(); | ||
| return; | ||
| } | ||
| } else { | ||
| fEntryOffset = new Int_t[fNevBufSize]; | ||
| } | ||
| if (20<flag && flag<40) { | ||
| for(int i=0; i<fNevBuf; i++){ | ||
| fEntryOffset[i] &= ~kDisplacementMask; | ||
| } | ||
| } | ||
| if (flag>40) { | ||
| fDisplacement = new Int_t[fNevBufSize]; | ||
| // ReadArray will allocate this for us. | ||
| fDisplacement = nullptr; | ||
| b.ReadArray(fDisplacement); | ||
| } | ||
| } else if (mustGenerateOffsets) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.