Skip to content

Commit 9565b1d

Browse files
noferinishahor02
authored andcommitted
add protection for tof compressor
1 parent 14ee8ce commit 9565b1d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Detectors/TOF/compression/src/CompressorTask.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ void CompressorTask<RDH, verbose, paranoid>::run(ProcessingContext& pc)
122122

123123
/** initialise output message **/
124124
auto bufferSize = mOutputBufferSize >= 0 ? mOutputBufferSize + subspecBufferSize[subspec] : std::abs(mOutputBufferSize);
125+
auto bufferSizeDouble = bufferSize * 2;
125126
auto output = Output{headerOut.dataOrigin, "CRAWDATA", headerOut.subSpecification};
126127
auto&& v = pc.outputs().makeVector<char>(output);
127-
v.resize(bufferSize);
128+
v.resize(bufferSizeDouble);
128129
// Better way of doing this would be to used an offset, so that we can resize the vector
129130
// as well. However, this should be good enough because bufferSize overestimates the size
130131
// of the payload.
@@ -150,6 +151,10 @@ void CompressorTask<RDH, verbose, paranoid>::run(ProcessingContext& pc)
150151
headerOut.payloadSize += payloadOutSize;
151152
}
152153

154+
if (headerOut.payloadSize > bufferSizeDouble) {
155+
headerOut.payloadSize = 0; // put payload to zero, otherwise it will trigger a crash
156+
}
157+
153158
v.resize(headerOut.payloadSize);
154159
pc.outputs().adoptContainer(output, std::move(v), true, header::gSerializationMethodNone);
155160
}

0 commit comments

Comments
 (0)