]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
added buffer size protection for varying AliHLTTPCTrackSegment struct sizes and recov...
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 23 Jul 2008 07:31:56 +0000 (07:31 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 23 Jul 2008 07:31:56 +0000 (07:31 +0000)
HLT/TPCLib/AliHLTTPCEsdWriterComponent.cxx
HLT/TPCLib/AliHLTTPCEventStatisticsProducerComponent.cxx
HLT/TPCLib/AliHLTTPCMerger.cxx
HLT/TPCLib/AliHLTTPCTrackArray.cxx
HLT/TPCLib/AliHLTTPCTrackArray.h
HLT/TPCLib/AliHLTTPCTrackSegmentData.h

index 71f15df16a7f55db6c6aa5c26de392e4f6de2f64..5493d7ceffd89e43f299a1bca3b6c4b877487f3b 100644 (file)
@@ -205,8 +205,9 @@ int AliHLTTPCEsdWriterComponent::ProcessBlocks(TTree* pTree, AliESDEvent* pESD,
            AliHLTTPCTrackArray tracks;
            inPtr=(AliHLTTPCTrackletData*)iter->fPtr;
            HLTDebug("reading block %d (slice %d): %d tracklets", ndx, minslice, inPtr->fTrackletCnt);
-           tracks.FillTracks(inPtr->fTrackletCnt, inPtr->fTracklets, minslice, 0/*don't rotate*/);
-           if ((iResult=Tracks2ESD(&tracks, pESD))>=0) {
+           if ((iResult=tracks.FillTracksChecked(inPtr->fTracklets, inPtr->fTrackletCnt, iter->fSize, minslice, 0/*don't rotate*/))>=0) {
+             if ((iResult=Tracks2ESD(&tracks, pESD))>=0) {
+             }
            }
          } else {
            HLTError("invalid sector number");
index 368a7a22fbcb08be649e332b8dad53cbcec94a21..8fb9b4886bb7f8c41b4c7f70b001916fe4ca5aa0 100644 (file)
@@ -335,7 +335,7 @@ void AliHLTTPCEventStatisticsProducerComponent::AddTracks( void* ptr, Int_t slic
     bTransform = 1;
   }
   
-  fTracks->FillTracks( nTracks, segmentData, slice, bTransform );
+  fTracks->FillTracksChecked( segmentData, nTracks, 0, slice, bTransform );
 
 }
 
index 4e300e2f96bffcd75083228f3e83a6c90f210bff..da6c203724724d61349ef64885c5d79a83d58be1 100644 (file)
@@ -146,9 +146,9 @@ void AliHLTTPCMerger::FillTracks(Int_t ntracks, AliHLTTPCTrackSegmentData* tr)
   //Read tracks from shared memory (or memory)
   AliHLTTPCTrackArray *destination = GetInTracks(fCurrentTracks);
   if(Is2Global())
-    destination->FillTracks(ntracks, tr, fSlice);
+    destination->FillTracksChecked(tr, ntracks, 0, fSlice);
   else
-    destination->FillTracks(ntracks, tr);
+    destination->FillTracksChecked(tr, ntracks, 0);
 }
 
 void AliHLTTPCMerger::AddAllTracks()
index 5107b981e9eeac46ad775675d5bd238394e2e94f..c57bcc57d5b7a935a5d11df0c2184e667a14a44c 100644 (file)
@@ -242,11 +242,24 @@ void AliHLTTPCTrackArray::Remove(Int_t track)
   }
 }
 
-void AliHLTTPCTrackArray::FillTracks(Int_t ntracks, AliHLTTPCTrackSegmentData* tr,Int_t slice, Int_t bTransform)
+int AliHLTTPCTrackArray::FillTracks(Int_t ntracks, AliHLTTPCTrackSegmentData* tr, Int_t slice, Int_t bTransform)
 {
   //Read tracks from shared memory (or memory)
+  return FillTracksChecked(tr, ntracks, 0, slice, bTransform);
+}
+
+int AliHLTTPCTrackArray::FillTracksChecked(AliHLTTPCTrackSegmentData* tr, Int_t ntracks, unsigned int sizeInByte, Int_t slice, Int_t bTransform)
+{
+  //Read tracks from shared memory (or memory)
+  int iResult=0;
   AliHLTTPCTrackSegmentData *trs = tr;
   for(Int_t i=0; i<ntracks; i++){
+    if (sizeInByte>0 && 
+       (((AliHLTUInt8_t*)trs)+sizeof(AliHLTTPCTrackSegmentData)>((AliHLTUInt8_t*)tr)+sizeInByte ||
+        ((AliHLTUInt8_t*)trs)+sizeof(AliHLTTPCTrackSegmentData)+trs->fNPoints*sizeof(UInt_t)>((AliHLTUInt8_t*)tr)+sizeInByte)) {
+      iResult=-EDOM;
+      break;
+    }
     AliHLTTPCTrack *track = NextTrack(); 
     track->SetPt(trs->fPt);
     track->SetPterr(trs->fPterr);
@@ -339,6 +352,76 @@ void AliHLTTPCTrackArray::FillTracks(Int_t ntracks, AliHLTTPCTrackSegmentData* t
     tmpP += sizeof(AliHLTTPCTrackSegmentData)+trs->fNPoints*sizeof(UInt_t);
     trs = (AliHLTTPCTrackSegmentData*)tmpP;
   }
+
+  if (iResult==-EDOM) {
+    // try to recover the version 1 struct
+    Reset();
+    if ((iResult=FillTracksVersion1((AliHLTTPCTrackSegmentDataV1*)tr, ntracks, sizeInByte, slice, bTransform))>=0) {
+      LOG(AliHLTTPCLog::kWarning,"AliHLTTPCTrackArray::FillTracks","") << "version 1 track array recoverd (deprecated since r27415)" << ENDLOG;
+    }
+  }
+  if (iResult==-EDOM) {
+    Reset();
+    LOG(AliHLTTPCLog::kError,"AliHLTTPCTrackArray::FillTracks","") << "corrupted input data array" << ENDLOG;
+  }
+
+  return iResult;
+}
+
+int AliHLTTPCTrackArray::FillTracksVersion1(AliHLTTPCTrackSegmentDataV1* tr, Int_t ntracks, unsigned int sizeInByte, Int_t slice, Int_t bTransform)
+{
+  //Read tracks from shared memory (or memory)
+  int iResult=0;
+  AliHLTTPCTrackSegmentDataV1 *trs = tr;
+  for(Int_t i=0; i<ntracks; i++){
+    if (sizeInByte>0 && 
+       (((AliHLTUInt8_t*)trs)+sizeof(AliHLTTPCTrackSegmentDataV1)>((AliHLTUInt8_t*)tr)+sizeInByte ||
+        ((AliHLTUInt8_t*)trs)+sizeof(AliHLTTPCTrackSegmentDataV1)+trs->fNPoints*sizeof(UInt_t)>((AliHLTUInt8_t*)tr)+sizeInByte)) {
+      iResult=-EDOM;
+      break;
+    }
+    AliHLTTPCTrack *track = NextTrack(); 
+    track->SetPt(trs->fPt);
+    track->SetPterr(trs->fPterr);
+    Float_t psi[1];
+    psi[0]=trs->fPsi;
+    if (slice>=0 && bTransform!=0)  {
+      AliHLTTPCTransform::Local2GlobalAngle(psi,slice);
+    }
+    track->SetPsi(psi[0]);
+    track->SetTgl(trs->fTgl);
+    track->SetPsierr(trs->fPsierr);
+    track->SetTglerr(trs->fTglerr);
+    track->SetNHits(trs->fNPoints);
+    track->SetCharge(trs->fCharge);
+    Float_t first[3];
+    first[0]=trs->fX;first[1]=trs->fY;first[2]=trs->fZ;
+    if (slice>=0 && bTransform!=0)  {
+      AliHLTTPCTransform::Local2Global(first,slice);
+    }
+    track->SetFirstPoint(first[0],first[1],first[2]);
+    Float_t last[3];
+    last[0]=trs->fLastX;last[1]=trs->fLastY;last[2]=trs->fLastZ;
+    if (slice>=0 && bTransform!=0)  {
+      AliHLTTPCTransform::Local2Global(last,slice);
+    }
+    track->SetLastPoint(last[0],last[1],last[2]);
+    track->SetHits( trs->fNPoints, trs->fPointIDs );
+
+    track->SetSector(slice);
+    if ( trs->fPt == -9876.0 ||  trs->fPt == -1.0) {
+      track->SetPhi0(atan2(first[1],first[0]));
+      track->SetKappa(1.0);
+      track->SetRadius(999999.0);
+    } else {
+      track->CalculateHelix();
+    }
+
+    UChar_t *tmpP = (UChar_t*)trs;
+    tmpP += sizeof(AliHLTTPCTrackSegmentDataV1)+trs->fNPoints*sizeof(UInt_t);
+    trs = (AliHLTTPCTrackSegmentDataV1*)tmpP;
+  }
+  return iResult;
 }
 
 UInt_t AliHLTTPCTrackArray::GetOutSize()
index 4b74be439e5811d9298a8842b28fec3017d6b9f7..c99fd4bdad36c509a96b6f14d104e23dc7605846 100644 (file)
@@ -19,6 +19,7 @@
 class AliHLTTPCConfMapTrack;
 class AliHLTTPCTrack;
 class AliHLTTPCTrackSegmentData;
+class AliHLTTPCTrackSegmentDataV1;
 
 /**
  * @class AliHLTTPCTrackArray
@@ -100,17 +101,43 @@ class AliHLTTPCTrackArray {
   void QSort( AliHLTTPCTrack **a, Int_t first, Int_t last);
   Int_t TrackCompare(AliHLTTPCTrack *a, AliHLTTPCTrack *b) const;
 
+  /**
+   * Fill track array from track segment array.
+   * Old method excluding buffer protection kept for backward compatibility.
+   * Forwarded to FillTracksChecked().
+   * @param ntracks      size of the input array
+   * @param tr           array of AliHLTTrackSegmentData
+   * @param slice        slice no to transform the tracks to
+   * @param bTransform   transform to global coordinates if 1
+   */
+  int FillTracks(Int_t ntracks, AliHLTTPCTrackSegmentData* tr, Int_t slice=-1, Int_t bTransform=1);
+
   /**
    * Fill track array from track segment array.
    * Reads the track from an array of AliHLTTrackSegmentData. The coordinates
    * are transformed to global coordinates if the slice parameter is specified.
    * In that case to internal slice variable is set to zero.
+   * 
+   * The sizeInByte parameter allows an additional buffer protection if
+   * non-zero. The size of the AliHLTTPCTrackSegmentData is not fixed due to
+   * variable array at the end of the structure. The pointer to the next
+   * entry must be set according to the variable array.
    * @param ntracks      size of the input array
    * @param tr           array of AliHLTTrackSegmentData
+   * @param sizeInByte   additional size protection
    * @param slice        slice no to transform the tracks to
    * @param bTransform   transform to global coordinates if 1
    */
-  void FillTracks(Int_t ntracks, AliHLTTPCTrackSegmentData* tr,Int_t slice=-1, Int_t bTransform=1);
+  int FillTracksChecked(AliHLTTPCTrackSegmentData* tr, Int_t ntracks, unsigned int sizeInByte, Int_t slice=-1, Int_t bTransform=1);
+
+  /**
+   * Fill array from version1 structure.
+   * The version 1 of ALiHLTTPCTrackSegmentData was valid until July 2008
+   * revision 27415.
+   *
+   * Similar behavior like FillTracksChecked.
+   */
+  int FillTracksVersion1(AliHLTTPCTrackSegmentDataV1* tr, Int_t ntracks, unsigned int sizeInByte, Int_t slice=-1, Int_t bTransform=1);
 
   UInt_t WriteTracks(AliHLTTPCTrackSegmentData* tr); //Write tracks
   UInt_t WriteTracks(UInt_t & ntracks,AliHLTTPCTrackSegmentData* tr); //Write tracks
index 60888f063a91f8433397831069e6ad8782e6ac31..367f921818558e01089f9c1ac22aba632369852f 100644 (file)
@@ -58,4 +58,36 @@ struct AliHLTTPCTrackSegmentData
 
 typedef struct AliHLTTPCTrackSegmentData AliHLTTPCTrackSegmentData;
 
+/**
+ * @struct AliHLTTPCTrackSegmentDataV1
+ * Former structure track segments, valid until July 2008
+ * revision 27415
+ *
+ * @ingroup alihlt_tpc_datastructs
+ */
+struct AliHLTTPCTrackSegmentDataV1
+    {
+       Float_t fX;
+       Float_t fY;
+       Float_t fZ;
+        Float_t fLastX;
+        Float_t fLastY;
+        Float_t fLastZ;
+       Double_t fPt;
+       Double_t fPsi;
+        Double_t fTgl;
+       Double_t fPterr;
+       Double_t fPsierr;
+        Double_t fTglerr;
+        Int_t fCharge;
+       UInt_t  fNPoints;
+#if defined(__HP_aCC) || defined(__DECCXX) || defined(__SUNPRO_CC)
+       UInt_t  fPointIDs[1];
+#else
+       UInt_t  fPointIDs[0];
+#endif
+    };
+
+typedef struct AliHLTTPCTrackSegmentDataV0 AliHLTTPCTrackSegmentDataV0;
+
 #endif /* _ALIHLTTPCTRACKSEGMENTDATA_H_ */