Skip to content

Commit

Permalink
adding protection in tof-compressor
Browse files Browse the repository at this point in the history
  • Loading branch information
noferini committed Oct 14, 2023
1 parent 4f15319 commit 888d9c6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Compressor
inline bool run()
{
rewind();
mEncoderPointerMax = reinterpret_cast<uint32_t*>(mEncoderBuffer + mEncoderBufferSize);
if (mDecoderCONET) {
mDecoderPointerMax = reinterpret_cast<const uint32_t*>(mDecoderBuffer + mDecoderBufferSize);
while (mDecoderPointer < mDecoderPointerMax) {
Expand Down
11 changes: 11 additions & 0 deletions Detectors/TOF/compression/src/Compressor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ bool Compressor<RDH, verbose, paranoid>::processHBF()
}

/** copy RDH open to encoder buffer **/

if (mEncoderPointer + mDecoderRDH->headerSize >= mEncoderPointerMax) {
LOG(error) << "link = " << rdh->feeId << ": beyond the buffer size mEncoderPointer+mDecoderRDH->headerSize = " << mEncoderPointer + mDecoderRDH->headerSize << " >= "
<< "mEncoderPointerMax = " << mEncoderPointerMax;
return true;
}
std::memcpy(mEncoderPointer, mDecoderRDH, mDecoderRDH->headerSize);
mEncoderPointer = reinterpret_cast<uint32_t*>(reinterpret_cast<char*>(mEncoderPointer) + rdh->headerSize);

Expand Down Expand Up @@ -246,6 +252,11 @@ bool Compressor<RDH, verbose, paranoid>::processHBF()

/** copy RDH close to encoder buffer **/
/** CAREFUL WITH THE PAGE COUNTER **/
if (mEncoderPointer + rdh->headerSize >= mEncoderPointerMax) {
LOG(error) << "link = " << rdh->feeId << ": beyond the buffer size mEncoderPointer+rdh->headerSize = " << mEncoderPointer + rdh->headerSize << " >= "
<< "mEncoderPointerMax = " << mEncoderPointerMax;
return true;
}
mEncoderRDH = reinterpret_cast<RDH*>(mEncoderPointer);
std::memcpy(mEncoderRDH, rdh, rdh->headerSize);
mEncoderRDH->memorySize = rdh->headerSize;
Expand Down
2 changes: 1 addition & 1 deletion Detectors/TOF/compression/src/tof-compressor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
outputs,
algoSpec,
Options{
{"tof-compressor-output-buffer-size", VariantType::Int, 0, {"Encoder output buffer size (in bytes). Zero = automatic (careful)."}},
{"tof-compressor-output-buffer-size", VariantType::Int, 1048576, {"Encoder output buffer size (in bytes). Zero = automatic (careful)."}},
{"tof-compressor-conet-mode", VariantType::Bool, false, {"Decoder CONET flag"}},
{"tof-compressor-decoder-verbose", VariantType::Bool, false, {"Decoder verbose flag"}},
{"tof-compressor-encoder-verbose", VariantType::Bool, false, {"Encoder verbose flag"}},
Expand Down

0 comments on commit 888d9c6

Please sign in to comment.