@@ -161,6 +161,7 @@ static myoff_t pos;
161
161
static int offsetCorrection = 0 ;
162
162
163
163
static BOOL warn115_240 = FALSE;
164
+ static BOOL corruptData = FALSE;
164
165
165
166
static time_t startTime = 0 ;
166
167
static time_t endTime = 0 ;
@@ -243,6 +244,7 @@ int main( int argc, char *argv[] )
243
244
244
245
int sectionCount ;
245
246
int recordSubTypeVersion ;
247
+ int triplet1Offset ;
246
248
247
249
infoStream = stdout ;
248
250
@@ -697,7 +699,18 @@ int main( int argc, char *argv[] )
697
699
/*******************************************************************/
698
700
offsetBlockStart = & pSMFMQRecord -> s [0 ];
699
701
offsetBlockType = BT_TRIPLET ;
700
- p = & dataBuf [conv32 (pSMFMQRecord -> s [0 ].offset )];
702
+ triplet1Offset = conv32 (pSMFMQRecord -> s [0 ].offset );
703
+ p = & dataBuf [triplet1Offset ];
704
+
705
+ /*
706
+ debugf(2,"Current file offset: 0x%08X\n",currentOffset);
707
+ printDEBUG("INPUT BUF",dataBuf,offset);
708
+ debugf(2,"\n p=%p bytesread=%d offset=%d\n",p,bytesRead+4,offset);
709
+ debugf(2," trip[0] tripOffset=%d [0x%08X] len=%d count=%d\n", triplet1Offset,triplet1Offset,
710
+ conv16(pSMFMQRecord->s[0].l),
711
+ conv16(pSMFMQRecord->s[0].n));
712
+ */
713
+
701
714
if (conv16 (pSMFMQRecord -> s [0 ].l ) == 4 ) /* There is no QWHS */
702
715
{
703
716
sectionCount = 2 ; /* 1 extra triplet beyond the QWHS location */
@@ -708,7 +721,24 @@ int main( int argc, char *argv[] )
708
721
else
709
722
{
710
723
char * dt [2 ];
724
+ int qwshlen ;
725
+
711
726
pqwhs = (qwhs * )p ;
727
+ qwshlen = conv16 (pqwhs -> qwhslen );
728
+ if (debugLevel >= 2 ) {
729
+ printDEBUG ("QWHS" ,p ,(qwshlen != 0 )?qwshlen :0x30 );
730
+ }
731
+ if (qwshlen <= 0 )
732
+ {
733
+ FILE * dfp = printDEBUGStream ();
734
+ fprintf (stderr ,"Error: Data at file offset 0x%08X appears corrupt. Exiting the formatter.\n" ,currentOffset );
735
+ if (dfp ) {
736
+ fprintf (dfp , "Error: Data at file offset 0x%08X appears corrupt. Exiting the formatter.\n" ,currentOffset );
737
+ }
738
+ corruptData = TRUE;
739
+ continue ;
740
+ }
741
+
712
742
sectionCount = pqwhs -> qwhsnsda [0 ];
713
743
convDate (pqwhs -> qwhsstck ,dt );
714
744
strcpy (commonF .stckFormatDate ,dt [0 ]);
@@ -736,7 +766,7 @@ int main( int argc, char *argv[] )
736
766
}
737
767
break ;
738
768
739
- case SMFTYPE_ZCEE :
769
+ case SMFTYPE_ZCEE :
740
770
recordSubTypeVersion = conv32 (pSMFMQRecord -> Header .u .v );
741
771
742
772
switch (recordSubTypeVersion )
@@ -773,8 +803,9 @@ int main( int argc, char *argv[] )
773
803
}
774
804
}
775
805
776
- if (pqwhs != NULL )
777
- debugf (3 ,"Section count %d for %4.4s, qwhslen=%d\n" ,sectionCount ,commonF .qMgr ,conv16 (pqwhs -> qwhslen ));
806
+ if (pqwhs != NULL ) {
807
+ debugf (3 ,"Section count %d for %4.4s, qwhslen=%d\n" ,sectionCount ,commonF .qMgr ,conv16 (pqwhs -> qwhslen ));
808
+ }
778
809
779
810
/*********************************************************************/
780
811
/* Once we know how many sections there are, copy the triplet values */
@@ -786,8 +817,9 @@ int main( int argc, char *argv[] )
786
817
/*********************************************************************/
787
818
recLength = getOffsets (sectionCount ,offsetBlockStart , offsetBlockType , recordType ,subTypesValid , currentOffset );
788
819
currentOffset += recLength ;
789
- if (debugLevel >= 2 )
820
+ if (debugLevel >= 2 ) {
790
821
printDEBUG ("FULL RECORD" ,dataBuf + offsetCorrection ,recLength );
822
+ }
791
823
792
824
793
825
/*********************************************************************/
@@ -1185,7 +1217,7 @@ int main( int argc, char *argv[] )
1185
1217
exit (0 );
1186
1218
}
1187
1219
}
1188
- } while (0 != bytesRead && totalRecords < maxRecords );
1220
+ } while (0 != bytesRead && totalRecords < maxRecords && ! corruptData );
1189
1221
1190
1222
/***********************************************************************/
1191
1223
/* Cleanup and exit. If we get here normally, then the checkpoint */
@@ -1740,26 +1772,20 @@ int getOffsets(int sectionCount,void *offsetBlockStart, int offsetBlockType, int
1740
1772
{
1741
1773
if (recordType == amsType )
1742
1774
{
1743
- fprintf ( infoStream , "Highest doublet = %d RecLength = %d New Offset = %lld\n" ,
1775
+ debugf ( 3 , "Highest doublet = %d RecLength = %d New Offset = %lld\n" ,
1744
1776
h , recLength , currentOffset );
1745
- if ( debugLevel >= 4 )
1777
+ for ( i = 0 ; i < sectionCount ; i ++ )
1746
1778
{
1747
- for (i = 0 ;i < sectionCount ;i ++ )
1748
- {
1749
- fprintf (infoStream ,"Doublet %d - offset=%d len=%d \n" ,i ,doublet [i ].offset ,doublet [i ].l );
1750
- }
1779
+ debugf (4 ,"Doublet %d - offset=%d len=%d \n" ,i ,doublet [i ].offset ,doublet [i ].l );
1751
1780
}
1752
1781
}
1753
1782
else
1754
1783
{
1755
- fprintf ( infoStream , "Highest triple = %d RecLength = %d New Offset = %lld\n" ,
1784
+ debugf ( 3 , "Highest triple = %d RecLength = %d New Offset = %lld\n" ,
1756
1785
h , recLength , currentOffset );
1757
- if ( debugLevel >= 4 )
1786
+ for ( i = 0 ; i < sectionCount ; i ++ )
1758
1787
{
1759
- for (i = 0 ;i < sectionCount ;i ++ )
1760
- {
1761
- fprintf (infoStream ,"Triplet %d - offset=%d len=%d count=%d\n" ,i ,triplet [i ].offset ,triplet [i ].l ,triplet [i ].n );
1762
- }
1788
+ debugf (4 ,"Triplet %d - offset=%d len=%d count=%d\n" ,i ,triplet [i ].offset ,triplet [i ].l ,triplet [i ].n );
1763
1789
}
1764
1790
}
1765
1791
}
0 commit comments