@@ -113,14 +113,15 @@ int TPCClusterDecompressor::decompress(const CompressedClusters* clustersCompres
113113 }
114114 offset += clustersCompressed->nTrackClusters [i] - j;
115115 }
116- ClusterNative* clusterBuffer = allocator (clustersCompressed->nAttachedClusters + clustersCompressed->nUnattachedClusters );
116+ size_t nTotalClusters = clustersCompressed->nAttachedClusters + clustersCompressed->nUnattachedClusters ;
117+ ClusterNative* clusterBuffer = allocator (nTotalClusters);
117118 unsigned int offsets[NSLICES ][GPUCA_ROW_COUNT ];
118119 offset = 0 ;
119120 for (unsigned int i = 0 ; i < NSLICES ; i++) {
120121 for (unsigned int j = 0 ; j < GPUCA_ROW_COUNT ; j++) {
121- clustersNative.nClusters [i][j] = clusters[i][j].size () + clustersCompressed->nSliceRowClusters [i * GPUCA_ROW_COUNT + j];
122+ clustersNative.nClusters [i][j] = clusters[i][j].size () + ((i * GPUCA_ROW_COUNT + j >= clustersCompressed->nSliceRows ) ? 0 : clustersCompressed-> nSliceRowClusters [i * GPUCA_ROW_COUNT + j]) ;
122123 offsets[i][j] = offset;
123- offset += clustersCompressed->nSliceRowClusters [i * GPUCA_ROW_COUNT + j];
124+ offset += (i * GPUCA_ROW_COUNT + j >= clustersCompressed-> nSliceRows ) ? 0 : clustersCompressed->nSliceRowClusters [i * GPUCA_ROW_COUNT + j];
124125 }
125126 }
126127 clustersNative.clustersLinear = clusterBuffer;
@@ -135,8 +136,11 @@ int TPCClusterDecompressor::decompress(const CompressedClusters* clustersCompres
135136 unsigned int time = 0 ;
136137 unsigned short pad = 0 ;
137138 ClusterNative* cl = buffer + clusters[i][j].size ();
138- unsigned int end = offsets[i][j] + clustersCompressed->nSliceRowClusters [i * GPUCA_ROW_COUNT + j];
139+ unsigned int end = offsets[i][j] + ((i * GPUCA_ROW_COUNT + j >= clustersCompressed->nSliceRows ) ? 0 : clustersCompressed-> nSliceRowClusters [i * GPUCA_ROW_COUNT + j]) ;
139140 for (unsigned int k = offsets[i][j]; k < end; k++) {
141+ /* if (cl >= clustersNative.clustersLinear + nTotalClusters) {
142+ throw std::runtime_error("Bad TPC CTF data, decoded more clusters than announced");
143+ }*/
140144 if (clustersCompressed->nComppressionModes & GPUSettings::CompressionDifferences) {
141145 unsigned int timeTmp = clustersCompressed->timeDiffU [k];
142146 if (timeTmp & 800000 ) {
0 commit comments