Skip to content

Commit 4340463

Browse files
committed
add overflow check for chunk and block size and file chunkPosition_ and bufferPosition_
1 parent 77bc9a2 commit 4340463

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

EventFilter/Utilities/interface/FedRawDataInputSource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class FedRawDataInputSource : public edm::RawInputSource {
8888

8989
std::string defPath_;
9090

91+
unsigned int paramChunkSize_; // chunk size in MB
92+
unsigned int paramBlockSize_; // read/write block size in MB
9193
unsigned int eventChunkSize_; // for buffered read-ahead
9294
unsigned int eventChunkBlock_; // how much read(2) asks at the time
9395
unsigned int readBlocks_;

EventFilter/Utilities/src/FedRawDataInputSource.cc

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ using namespace edm::streamer;
5353
FedRawDataInputSource::FedRawDataInputSource(edm::ParameterSet const& pset, edm::InputSourceDescription const& desc)
5454
: edm::RawInputSource(pset, desc),
5555
defPath_(pset.getUntrackedParameter<std::string>("buDefPath", "")),
56-
eventChunkSize_(pset.getUntrackedParameter<unsigned int>("eventChunkSize", 32) * 1048576),
57-
eventChunkBlock_(pset.getUntrackedParameter<unsigned int>("eventChunkBlock", 32) * 1048576),
56+
paramChunkSize_(pset.getUntrackedParameter<unsigned int>("eventChunkSize", 32)),
57+
paramBlockSize_(pset.getUntrackedParameter<unsigned int>("eventChunkBlock", 32)),
5858
numConcurrentReads_(pset.getUntrackedParameter<int>("numConcurrentReads", -1)),
5959
numBuffers_(pset.getUntrackedParameter<unsigned int>("numBuffers", 2)),
6060
maxBufferedFiles_(pset.getUntrackedParameter<unsigned int>("maxBufferedFiles", 2)),
@@ -77,6 +77,17 @@ FedRawDataInputSource::FedRawDataInputSource(edm::ParameterSet const& pset, edm:
7777
eventsThisLumi_(0) {
7878
char thishost[256];
7979
gethostname(thishost, 255);
80+
81+
//ensure 32-bit buffer limits
82+
if (paramChunkSize_ > 4095)
83+
throw cms::Exception("FedRawDataInputSource::fillFEDRawDataCollection")
84+
<< "Invalid chunk size of " << paramChunkSize_ << " MB. Only less than 4GB is supported.";
85+
if (paramBlockSize_ > 4095)
86+
throw cms::Exception("FedRawDataInputSource::fillFEDRawDataCollection")
87+
<< "Invalid block size of " << paramBlockSize_ << " MB. Only less than 4GB is supported.";
88+
eventChunkSize_ = paramChunkSize_ << 20;
89+
eventChunkBlock_ = paramBlockSize_ << 20;
90+
8091
edm::LogInfo("FedRawDataInputSource") << "Construction. read-ahead chunk size -: " << std::endl
8192
<< (eventChunkSize_ / 1048576) << " MB on host " << thishost;
8293

@@ -476,6 +487,13 @@ inline evf::EvFDaqDirector::FileStatus FedRawDataInputSource::getNextEvent() {
476487
//advance buffer position to skip file header (chunk will be acquired later)
477488
currentFile_->chunkPosition_ += currentFile_->rawHeaderSize_;
478489
currentFile_->bufferPosition_ += currentFile_->rawHeaderSize_;
490+
491+
if (currentFile_->chunkPosition_ > UINT32_MAX)
492+
throw cms::Exception("FedRawDataInputSource::getNextEvent")
493+
<< "chunkPosition_ overflow " << currentFile_->chunkPosition_;
494+
if (currentFile_->bufferPosition_ > UINT32_MAX)
495+
throw cms::Exception("FedRawDataInputSource::getNextEvent")
496+
<< "bufferPosition_ overflow " << currentFile_->bufferPosition_;
479497
}
480498

481499
//file is too short
@@ -532,6 +550,11 @@ inline evf::EvFDaqDirector::FileStatus FedRawDataInputSource::getNextEvent() {
532550
chunkIsFree_ = true;
533551
} else {
534552
//header was contiguous, but check if payload fits the chunk
553+
554+
if (currentFile_->chunkPosition_ > UINT32_MAX)
555+
throw cms::Exception("FedRawDataInputSource::getNextEvent")
556+
<< "chunkPosition_ overflow " << currentFile_->chunkPosition_;
557+
535558
if (eventChunkSize_ - (uint32_t)currentFile_->chunkPosition_ < msgSize) {
536559
//rewind to header start position
537560
currentFile_->rewindChunk(FRDHeaderVersionSize[detectedFRDversion_]);
@@ -1528,6 +1551,11 @@ void FedRawDataInputSource::readNextChunkIntoBuffer(InputFile* file) {
15281551
}
15291552
} else {
15301553
//event didn't fit in last chunk, so leftover must be moved to the beginning and completed
1554+
1555+
if (file->chunkPosition_ > UINT32_MAX)
1556+
throw cms::Exception("FedRawDataInputSource::readNextChunkIntoBuffer")
1557+
<< "chunkPosition_ overflow " << file->chunkPosition_;
1558+
15311559
uint32_t existingSizeLeft = eventChunkSize_ - (uint32_t)file->chunkPosition_;
15321560
memmove((void*)file->chunks_[0]->buf_, file->chunks_[0]->buf_ + file->chunkPosition_, existingSizeLeft);
15331561

0 commit comments

Comments
 (0)