# HG changeset patch # User Ross Qin # Date 1288687641 -28800 # Node ID bc9ef8cca9ec4d1b042da7cc45dba424c1ab9eb0 # Parent ff8ff850b0cf91e7a2065ca78278860fe861d69a revert the change to rofsbuild image format, but add checking codes to prevent address overflow diff -r ff8ff850b0cf -r bc9ef8cca9ec imgtools/romtools/rofsbuild/r_build.cpp --- a/imgtools/romtools/rofsbuild/r_build.cpp Tue Nov 02 09:31:04 2010 +0800 +++ b/imgtools/romtools/rofsbuild/r_build.cpp Tue Nov 02 16:47:21 2010 +0800 @@ -82,7 +82,7 @@ { TRofsEntry* iEntry; TBool iIsDir; - TUint32 iOffset; + TUint16 iOffset; }; int compare(const void* l, const void* r) @@ -621,15 +621,31 @@ entry = pFileEntry; //Offset in 32bit words from start of file block - array[index].iOffset = (TUint32) ((((TUint8*) entry) - fileBlockBase) >> 2); + TUint32 offset = ((((TUint8*) entry) - fileBlockBase) >> 2); + + if(offset > 0xFFFF) + { + printf("ERROR: Offset overflow: name=%s, OFFSET = %d\n", node->iName, offset); + throw "fail"; + } + + + array[index].iOffset = (TUint16) offset; array[index].iIsDir = EFalse; } else { entry = pDirEntry; + TUint32 offset = ((((TUint8*) entry) - dirBlockBase) >> 2); + if(offset > 0xFFFF) + { + printf("ERROR: Offset overflow: name=%s, OFFSET = %d\n", node->iName, offset); + throw "fail"; + } + //Offset in 32bit words from start of directory block - array[index].iOffset = (TUint32) ((((TUint8*) entry) - dirBlockBase) >> 2); + array[index].iOffset = (TUint16) offset; array[index].iIsDir = ETrue; } array[index].iEntry = entry;