revert the change to rofsbuild image format, but add checking codes to prevent address overflow
authorRoss Qin <ross.qin@nokia.com>
Tue, 02 Nov 2010 16:47:21 +0800
changeset 672 bc9ef8cca9ec
parent 671 ff8ff850b0cf
child 673 7ae5f757318b
revert the change to rofsbuild image format, but add checking codes to prevent address overflow
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;