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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion EventFilter/Utilities/plugins/FRDStreamSource.cc
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
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
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
7 changes: 5 additions & 2 deletions IOPool/Streamer/interface/FRDEventMessage.h
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,9 @@ 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)};
const size_t FRDHeaderMaxVersion = 6;
const std::array<uint32,FRDHeaderMaxVersion+1> FRDHeaderVersionSize = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

Suggested change
const size_t FRDHeaderMaxVersion = 6;
const std::array<uint32,FRDHeaderMaxVersion+1> FRDHeaderVersionSize = {
constexpr size_t FRDHeaderMaxVersion = 6;
constexpr std::array<uint32,FRDHeaderMaxVersion+1> FRDHeaderVersionSize = {

? (although the practical impact may be negiligble)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems fine, will add it with code checks fix.

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