Skip to content
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

DAQ: fix FedRawData source going out of array boundaries #32116

Merged
merged 4 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion EventFilter/Utilities/plugins/FRDStreamSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool FRDStreamSource::setRunAndEventInfo(edm::EventID& id,
if (detectedFRDversion_ == 0) {
fin_.read((char*)&detectedFRDversion_, sizeof(uint16_t));
fin_.read((char*)&flags_, sizeof(uint16_t));
assert(detectedFRDversion_ > 0 && detectedFRDversion_ <= 6);
assert(detectedFRDversion_ > 0 && detectedFRDversion_ <= FRDHeaderMaxVersion);
if (buffer_.size() < FRDHeaderVersionSize[detectedFRDversion_])
buffer_.resize(FRDHeaderVersionSize[detectedFRDversion_]);
*((uint32_t*)(&buffer_[0])) = detectedFRDversion_;
Expand Down
1 change: 1 addition & 0 deletions EventFilter/Utilities/plugins/RawEventOutputModuleForBU.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void RawEventOutputModuleForBU<Consumer>::write(edm::EventForOutput const& e) {
e.getByToken(token_, fedBuffers);

// determine the expected size of the FRDEvent IN BYTES !!!!!
assert(frdVersion_ <= FRDHeaderMaxVersion);
int headerSize = FRDHeaderVersionSize[frdVersion_];
int expectedSize = headerSize;
int nFeds = frdVersion_ < 3 ? 1024 : FEDNumbering::lastFEDId() + 1;
Expand Down
4 changes: 2 additions & 2 deletions EventFilter/Utilities/src/FedRawDataInputSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ inline evf::EvFDaqDirector::FileStatus FedRawDataInputSource::getNextEvent() {

if (detectedFRDversion_ == 0) {
detectedFRDversion_ = *((uint16_t*)dataPosition);
if (detectedFRDversion_ > 6)
if (detectedFRDversion_ > FRDHeaderMaxVersion)
throw cms::Exception("FedRawDataInputSource::getNextEvent")
<< "Unknown FRD version -: " << detectedFRDversion_;
assert(detectedFRDversion_ >= 1);
Expand Down Expand Up @@ -1341,7 +1341,7 @@ void FedRawDataInputSource::readWorker(unsigned int tid) {
if (detectedFRDversion_ == 0 && chunk->offset_ == 0) {
detectedFRDversion_ = *((uint16_t*)(chunk->buf_ + file->rawHeaderSize_));
}
assert(detectedFRDversion_ <= 6);
assert(detectedFRDversion_ <= FRDHeaderMaxVersion);
chunk->readComplete_ =
true; //this is atomic to secure the sequential buffer fill before becoming available for processing)
file->chunks_[chunk->fileIndex_] = chunk; //put the completed chunk in the file chunk vector at predetermined index
Expand Down
12 changes: 10 additions & 2 deletions IOPool/Streamer/interface/FRDEventMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@

#include "IOPool/Streamer/interface/MsgTools.h"

#include <array>

struct FRDEventHeader_V6 {
uint16 version_;
uint16 flags_;
Expand Down Expand Up @@ -123,8 +125,14 @@ struct FRDEventHeader_V1 {

const uint16 FRDEVENT_MASK_ISGENDATA = 1;

const uint32 FRDHeaderVersionSize[6] = {
0, 2 * sizeof(uint32), (4 + 1024) * sizeof(uint32), 7 * sizeof(uint32), 8 * sizeof(uint32), 6 * sizeof(uint32)};
constexpr size_t FRDHeaderMaxVersion = 6;
constexpr std::array<uint32, FRDHeaderMaxVersion + 1> FRDHeaderVersionSize{{0,
2 * sizeof(uint32),
(4 + 1024) * sizeof(uint32),
7 * sizeof(uint32),
8 * sizeof(uint32),
6 * sizeof(uint32),
6 * sizeof(uint32)}};

class FRDEventMsgView {
public:
Expand Down