improved robustness; format specifications changed from variables to defines to be...
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 10 Mar 2008 13:15:54 +0000 (13:15 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 10 Mar 2008 13:15:54 +0000 (13:15 +0000)
HLT/BASE/HOMER/AliHLTHOMERData.h
HLT/BASE/HOMER/AliHLTHOMERReader.cxx

index dbcf292..5d829f9 100644 (file)
@@ -124,33 +124,31 @@ typedef int key_t;
 //typedef homer_uint64 AliEventID_t;
 
 
-
-const unsigned kAttribute_8b_StartOffset = 0;
-const unsigned kByteOrderAttribute_8b_Offset = kAttribute_8b_StartOffset+0;
-const unsigned kVersionAttribute_8b_Offset = kAttribute_8b_StartOffset+1;
-const unsigned kAlignment_8b_StartOffset = 24;
-const unsigned kUInt64Alignment_8b_Offset = kAlignment_8b_StartOffset+0;
-const unsigned kUInt32Alignment_8b_Offset = kAlignment_8b_StartOffset+1;
-const unsigned kUInt16Alignment_8b_Offset = kAlignment_8b_StartOffset+2;
-const unsigned kUInt8Alignment_8b_Offset = kAlignment_8b_StartOffset+3;
-const unsigned kDoubleAlignment_8b_Offset = kAlignment_8b_StartOffset+4;
-const unsigned kFloatAlignment_8b_Offset = kAlignment_8b_StartOffset+5;
-
-
-const unsigned kID_64b_Offset = 1;
-const unsigned kLength_64b_Offset = 2;
-const unsigned kType_64b_Offset = 4;
-const unsigned kSubType1_64b_Offset = 5;
-const unsigned kSubType2_64b_Offset = 6;
-const unsigned kBirth_s_64b_Offset = 7;
-const unsigned kBirth_us_64b_Offset = 8;
-const unsigned kProducerNode_64b_Offset = 9;
-const unsigned kOffset_64b_Offset = 10;
-const unsigned kSize_64b_Offset = 11;
-const unsigned kStatusFlags_64b_Offset = 12;
-const unsigned kEnd_64b_Offset = 13;
-const unsigned kCount_64b_Words = kEnd_64b_Offset;
-
+#define kAttribute_8b_StartOffset     0
+#define kByteOrderAttribute_8b_Offset kAttribute_8b_StartOffset+0
+#define kVersionAttribute_8b_Offset   kAttribute_8b_StartOffset+1
+#define kAlignment_8b_StartOffset     24
+#define kUInt64Alignment_8b_Offset    kAlignment_8b_StartOffset+0
+#define kUInt32Alignment_8b_Offset    kAlignment_8b_StartOffset+1
+#define kUInt16Alignment_8b_Offset    kAlignment_8b_StartOffset+2
+#define kUInt8Alignment_8b_Offset     kAlignment_8b_StartOffset+3
+#define kDoubleAlignment_8b_Offset    kAlignment_8b_StartOffset+4
+#define kFloatAlignment_8b_Offset     kAlignment_8b_StartOffset+5
+
+
+#define kID_64b_Offset           1
+#define kLength_64b_Offset       2
+#define kType_64b_Offset         4
+#define kSubType1_64b_Offset     5
+#define kSubType2_64b_Offset     6
+#define kBirth_s_64b_Offset      7
+#define kBirth_us_64b_Offset     8
+#define kProducerNode_64b_Offset 9
+#define kOffset_64b_Offset      10
+#define kSize_64b_Offset        11
+#define kStatusFlags_64b_Offset 12
+#define kEnd_64b_Offset         13
+#define kCount_64b_Words        kEnd_64b_Offset
 
 // Possible values for fAttributes[kByteOrderAttribute]
 /* Keep this consistent with BCLNetworkData.hpp kLittleEndian/kBigEndian and AliHLTSubEventDataDescriptor.hpp */
index 2b9cb43..6674144 100644 (file)
@@ -345,6 +345,7 @@ AliHLTHOMERReader::AliHLTHOMERReader( const void* pBuffer, int size )
     else
        {
        fDataSourceCnt++;
+       fShmDataSourceCnt++;
        fDataSources[0].fNdx = 0;
        }
     }
@@ -847,7 +848,7 @@ int AliHLTHOMERReader::ReadNextEvent( bool useTimeout, unsigned long timeout )
            {
            fErrorConnection = n;
            fConnectionStatus=57;//EBADSLT;
-           return fConnectionStatus;
+           return ret;
            }
        }
     fCurrentEventID = eventID;
@@ -1213,15 +1214,23 @@ int AliHLTHOMERReader::ParseSourceData( DataSource& source )
     if ( source.fData )
        {
        homer_uint8 sourceByteOrder = ((homer_uint8*)source.fData)[ kByteOrderAttribute_8b_Offset ];
+       if (sourceByteOrder!=kHOMERLittleEndianByteOrder && sourceByteOrder!=kHOMERBigEndianByteOrder) return EBADMSG;
        homer_uint64 blockCnt = Swap( kHOMERNativeByteOrder, sourceByteOrder, ((homer_uint64*)source.fData)[ kSubType2_64b_Offset ] );
+       // block count is not related to size of the data in the way the
+       // following condition implies. But we can at least limit the block
+       // count for the case the data is corrupted
+       if (blockCnt>source.fDataSize) return EBADMSG;
        int ret=ReAllocBlocks( fMaxBlockCnt+blockCnt );
        if ( ret )
            return ret;
        homer_uint64 descrOffset = Swap( kHOMERNativeByteOrder, sourceByteOrder, ((homer_uint64*)source.fData)[ kOffset_64b_Offset ] );
        for ( homer_uint64 n = 0; n < blockCnt && fBlockCnt < fMaxBlockCnt; n++, fBlockCnt++ )
            {
+           if (descrOffset+kLength_64b_Offset>=source.fDataSize) return EBADMSG;
            homer_uint8* descr = ((homer_uint8*)source.fData)+descrOffset;
            unsigned descrLen = Swap( kHOMERNativeByteOrder, sourceByteOrder, ((homer_uint64*)descr)[ kLength_64b_Offset ] );
+           if (descrOffset+descrLen>=source.fDataSize) return EBADMSG;
+           if (Swap( kHOMERNativeByteOrder, sourceByteOrder, ((homer_uint64*)descr)[ kID_64b_Offset ] ) != HOMER_BLOCK_DESCRIPTOR_TYPEID) return ENOKEY;
            fBlocks[fBlockCnt].fSource = source.fNdx;
            fBlocks[fBlockCnt].fData = ((homer_uint8*)source.fData) + Swap( kHOMERNativeByteOrder, sourceByteOrder, ((homer_uint64*)descr)[ kOffset_64b_Offset ] );
            fBlocks[fBlockCnt].fLength = Swap( kHOMERNativeByteOrder, sourceByteOrder, ((homer_uint64*)descr)[ kSize_64b_Offset ] );