Hi,
few times per year we find corrupted .fpt files in databeses of our
customers. The problem is that this corruption is not detected by driver
and causes strange behavior. For example, application hangs-up, but do
not GPFs. After some tests we found, that it "hangs-up" because it uses
a huge amount of memory (ex. >= 1GB) and OS do a lot of disk swap thus
stops application and system. This memory usage is caused by reading
some memo value. Total memo file length is not big (1MB), but corrupted
.ftp blocks contains huge size values. I've wrote some code to test for
such memofields, but it would be nice to have some corruption detection
code in fpt driver.
Regards,
Mindaugas
#include "hbapi.h"
#include "hbrddfpt.h"
HB_FUNC( FPTTESTFIELD )
{
DBFAREAP pArea = ( DBFAREAP ) hb_rddGetCurrentWorkAreaPointer();
USHORT uiField = hb_parni( 1 );
ULONG ulBlock, ulSize, ulType;
BOOL bDeleted;
if( !pArea || !uiField || uiField > pArea->uiFieldCount ||
!pArea->fHasMemo || pArea->bMemoType != DB_MEMO_FPT )
{
hb_retl( FALSE );
return;
}
/* Force record read */
SELF_DELETED( pArea, &bDeleted );
if( hb_dbfGetMemoData( ( DBFAREAP ) pArea, uiField - 1, &ulBlock,
&ulSize, &ulType ) != SUCCESS )
{
hb_retl( FALSE );
return;
}
if( ulBlock > 0 )
{
FPTBLOCK fptBlock;
if( hb_fileReadAt( pArea->pMemoFile, ( BYTE * ) &fptBlock,
sizeof( FPTBLOCK ),
( HB_FOFFSET ) ulBlock * ( HB_FOFFSET )
pArea->uiMemoBlockSize ) != sizeof( FPTBLOCK ) )
{
hb_retl( FALSE );
return;
}
ulType = HB_GET_BE_UINT32( fptBlock.type );
ulSize = HB_GET_BE_UINT32( fptBlock.size );
if( ( ulType > FPTIT_TEXT && ulType < FPTIT_FLEX_GC ) ||
ulType > FPTIT_FLEX_COMPRCH ||
ulSize > 1048576 )
{
hb_retl( FALSE );
return;
}
}
hb_retl( TRUE );
}
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour