Skip to content

Commit 4876971

Browse files
committed
GPU dEdx: Fix possible buffer overflow when adding subThreshold clusters
1 parent 76a4eed commit 4876971

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

GPU/GPUTracking/dEdx/GPUdEdx.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
using namespace o2::gpu;
2121

22+
static_assert(GPUdEdx::MAX_NCL <= 255); // Must fit in mNClsROC (uint8_t)!
23+
2224
#ifndef GPUCA_GPUCODE_DEVICE
2325
GPUd() void GPUdEdx::clear()
2426
{

GPU/GPUTracking/dEdx/GPUdEdx.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class GPUdEdx
3636
GPUd() void fillSubThreshold(int32_t padRow);
3737
GPUd() void computedEdx(GPUdEdxInfo& output, const GPUParam& param);
3838

39+
static constexpr size_t MAX_NCL = GPUCA_ROW_COUNT;
40+
3941
private:
4042
GPUd() float GetSortTruncMean(GPUCA_PAR_DEDX_STORAGE_TYPE_A* array, int32_t count, int32_t trunclow, int32_t trunchigh);
4143
GPUd() void checkSubThresh(int32_t roc);
@@ -60,8 +62,6 @@ class GPUdEdx
6062
};
6163
#endif
6264

63-
static constexpr int32_t MAX_NCL = GPUCA_ROW_COUNT; // Must fit in mNClsROC (uint8_t)!
64-
6565
GPUCA_PAR_DEDX_STORAGE_TYPE_A mChargeTot[MAX_NCL]; // No need for default, just some memory
6666
GPUCA_PAR_DEDX_STORAGE_TYPE_A mChargeMax[MAX_NCL]; // No need for default, just some memory
6767
float mSubThreshMinTot = 0.f;
@@ -76,7 +76,7 @@ class GPUdEdx
7676
GPUdi() void GPUdEdx::checkSubThresh(int32_t roc)
7777
{
7878
if (roc != mLastROC) {
79-
if (mNSubThresh && mCount + mNSubThresh <= MAX_NCL) {
79+
if (mNSubThresh && mCount + mNSubThresh < MAX_NCL) {
8080
for (int32_t i = 0; i < mNSubThresh; i++) {
8181
mChargeTot[mCount] = (GPUCA_PAR_DEDX_STORAGE_TYPE_A)(mSubThreshMinTot * scalingFactor<GPUCA_PAR_DEDX_STORAGE_TYPE_A>::factor + scalingFactor<GPUCA_PAR_DEDX_STORAGE_TYPE_A>::round);
8282
mChargeMax[mCount++] = (GPUCA_PAR_DEDX_STORAGE_TYPE_A)(mSubThreshMinMax * scalingFactor<GPUCA_PAR_DEDX_STORAGE_TYPE_A>::factor + scalingFactor<GPUCA_PAR_DEDX_STORAGE_TYPE_A>::round);
@@ -94,16 +94,15 @@ GPUdi() void GPUdEdx::checkSubThresh(int32_t roc)
9494

9595
GPUdnii() void GPUdEdx::fillCluster(float qtot, float qmax, int32_t padRow, uint8_t sector, float trackSnp, float trackTgl, const GPUCalibObjectsConst& calib, float z, float pad, float relTime)
9696
{
97-
if (mCount >= MAX_NCL) {
98-
return;
99-
}
100-
10197
// container containing all the dE/dx corrections
10298
auto calibContainer = calib.dEdxCalibContainer;
10399
constexpr GPUTPCGeometry geo;
104100

105101
const int32_t roc = geo.GetROC(padRow);
106102
checkSubThresh(roc);
103+
if (mCount >= MAX_NCL) {
104+
return;
105+
}
107106
float snp2 = trackSnp * trackSnp;
108107
if (snp2 > GPUCA_MAX_SIN_PHI_LOW) {
109108
snp2 = GPUCA_MAX_SIN_PHI_LOW;

0 commit comments

Comments
 (0)