From 9bd6f29b819f3a756ff088455a4ea044b98f1d03 Mon Sep 17 00:00:00 2001 From: odjuvsla Date: Fri, 12 Feb 2010 01:13:19 +0000 Subject: [PATCH] - fixing protection against writing outside of buffer --- HLT/CALO/AliHLTCaloClusterizer.cxx | 27 ++++++++++++----- HLT/CALO/AliHLTCaloClusterizer.h | 47 +++++++++--------------------- 2 files changed, 34 insertions(+), 40 deletions(-) diff --git a/HLT/CALO/AliHLTCaloClusterizer.cxx b/HLT/CALO/AliHLTCaloClusterizer.cxx index a2bc5b269b3..17c2b3b99b4 100644 --- a/HLT/CALO/AliHLTCaloClusterizer.cxx +++ b/HLT/CALO/AliHLTCaloClusterizer.cxx @@ -94,7 +94,9 @@ AliHLTCaloClusterizer::ClusterizeEvent(Int_t nDigits, UInt_t availableSize, UInt { //see header file for documentation Int_t nRecPoints = 0; - + + fAvailableSize = availableSize; + fNDigits = nDigits; UInt_t maxRecPointSize = sizeof(AliHLTCaloRecPointDataStruct) + (sizeof(AliHLTCaloDigitDataStruct) << 7); //Reasonable estimate... @@ -108,10 +110,13 @@ AliHLTCaloClusterizer::ClusterizeEvent(Int_t nDigits, UInt_t availableSize, UInt { continue; } - if(availableSize < (totSize + maxRecPointSize)) + + if(fAvailableSize < (sizeof(AliHLTCaloRecPointDataStruct))) { - return -1; //Might get out of buffer, exiting + HLTError("Out of buffer, stopping clusterisation"); + return -1; } + // printf("cluster candidate!\n"); // First digit is placed at the fDigits member variable in the recpoint fDigitIndexPtr = &(fRecPointDataPtr->fDigits); @@ -131,7 +136,10 @@ AliHLTCaloClusterizer::ClusterizeEvent(Int_t nDigits, UInt_t availableSize, UInt nRecPoints++; // Scanning for the neighbours - ScanForNeighbourDigits(i, fRecPointDataPtr); + if(ScanForNeighbourDigits(i, fRecPointDataPtr) != 0) + { + return -1; + } totSize += sizeof(AliHLTCaloRecPointDataStruct) + (fDigitsInCluster-1)*sizeof(AliHLTCaloDigitDataStruct); fRecPointDataPtr->fMultiplicity = fDigitsInCluster; @@ -143,7 +151,7 @@ AliHLTCaloClusterizer::ClusterizeEvent(Int_t nDigits, UInt_t availableSize, UInt return nRecPoints; } -void +Int_t AliHLTCaloClusterizer::ScanForNeighbourDigits(Int_t index, AliHLTCaloRecPointDataStruct* recPoint) { //see header file for documentation @@ -161,7 +169,12 @@ AliHLTCaloClusterizer::ScanForNeighbourDigits(Int_t index, AliHLTCaloRecPointDat if(AreNeighbours(fDigitsPointerArray[index], fDigitsPointerArray[j])) { - // Assigning value to digit ptr + if(fAvailableSize < (sizeof(Int_t))) + { + HLTError("Out of buffer, stopping clusterisation"); + return -1; + } + // Assigning index to digit *fDigitIndexPtr = j; // Incrementing digit pointer to be ready for new entry fDigitIndexPtr++; @@ -174,7 +187,7 @@ AliHLTCaloClusterizer::ScanForNeighbourDigits(Int_t index, AliHLTCaloRecPointDat } } } - return; + return 0; } Int_t diff --git a/HLT/CALO/AliHLTCaloClusterizer.h b/HLT/CALO/AliHLTCaloClusterizer.h index 5c7587a36be..d71996dfc50 100644 --- a/HLT/CALO/AliHLTCaloClusterizer.h +++ b/HLT/CALO/AliHLTCaloClusterizer.h @@ -46,6 +46,7 @@ #include "AliHLTCaloConstantsHandler.h" //#include "AliPHOSGeometry.h" +#include "AliHLTLogging.h" class TClonesArray; class TString; @@ -63,7 +64,7 @@ class TString; */ -class AliHLTCaloClusterizer : public AliHLTCaloConstantsHandler +class AliHLTCaloClusterizer : public AliHLTCaloConstantsHandler, public AliHLTLogging { public: @@ -73,30 +74,7 @@ public: /** Destructor */ virtual ~AliHLTCaloClusterizer(); - -// /** Copy constructor */ -// AliHLTCaloClusterizer(const AliHLTCaloClusterizer &) : -// // AliHLTCaloBase(), -// AliHLTCaloConstants(NULL), -// fRecPointDataPtr(0), -// fDigitDataPtr(0), -// fEmcClusteringThreshold(0), -// fEmcMinEnergyThreshold(0), -// fEmcTimeGate(0), -// fDigitsInCluster(0), -// fDigitContainerPtr(0), -// fMaxDigitIndexDiff(2*NZROWSMOD) -// { -// //Copy constructor not implemented -// } - /** Assignment */ - AliHLTCaloClusterizer & operator = (const AliHLTCaloClusterizer) - { - //Assignment - return *this; - } - /** Set digit container */ void SetDigitContainer(AliHLTCaloDigitContainerDataStruct* digitContainerPtr) { fDigitContainerPtr = digitContainerPtr; } @@ -130,7 +108,7 @@ public: * @param digIndex index of the digit in the digit container * @param recPoint pointer to the current rec point */ - virtual void ScanForNeighbourDigits(Int_t digIndex, AliHLTCaloRecPointDataStruct* recPoint); + virtual Int_t ScanForNeighbourDigits(Int_t digIndex, AliHLTCaloRecPointDataStruct* recPoint); /** * Checks if two digits are neighbours @@ -173,18 +151,21 @@ protected: Int_t fNDigits; //COMMENT private: + + /** Size of the available write buffer */ + UInt_t fAvailableSize; //COMMENT - AliHLTCaloClusterizer(); - - AliHLTCaloClusterizer (const AliHLTCaloClusterizer &); -// AliHLTCaloClusterizer & operator = (const AliHLTCaloClusterizer &) -// { -// return *this; -// } + /** Default constructor, prohibited */ + AliHLTCaloClusterizer(); // COMMENT + + /** Copy constructor, prohibited */ + AliHLTCaloClusterizer (const AliHLTCaloClusterizer &); //COMMENT + + /** Assignment operator, prohibited */ + AliHLTCaloClusterizer & operator = (const AliHLTCaloClusterizer &); //COMMENT ClassDef(AliHLTCaloClusterizer, 0); - }; #endif -- 2.39.3