Skip to content

Commit 88d2f72

Browse files
committed
fixed --list command in presence of special blocks
block type RLE is special, compressed size is always 1. block type 3 is "reserved", aka not supported.
1 parent c523c93 commit 88d2f72

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

programs/fileio.c

+15-9
Original file line numberDiff line numberDiff line change
@@ -994,23 +994,29 @@ static int getFileInfo(fileInfo_t* info, const char* inFileName){
994994
{ int lastBlock = 0;
995995
do {
996996
BYTE blockHeaderBuffer[3];
997-
U32 blockHeader;
998-
int blockSize;
999997
size_t const readBytes = fread(blockHeaderBuffer, 1, 3, srcFile);
1000998
if (readBytes != 3) {
1001999
DISPLAY("There was a problem reading the block header\n");
10021000
detectError = 1;
10031001
break;
10041002
}
1005-
blockHeader = MEM_readLE24(blockHeaderBuffer);
1006-
lastBlock = blockHeader & 1;
1007-
blockSize = blockHeader >> 3; /* Warning : does not work when block is RLE type */
1008-
{ int const ret = fseek(srcFile, blockSize, SEEK_CUR);
1009-
if (ret != 0) {
1010-
DISPLAY("Error: could not skip to end of block\n");
1003+
{ U32 const blockHeader = MEM_readLE24(blockHeaderBuffer);
1004+
U32 const blockTypeID = (blockHeader >> 1) & 3;
1005+
U32 const isRLE = (blockTypeID == 1);
1006+
U32 const isWrongBlock = (blockTypeID == 3);
1007+
long const blockSize = isRLE ? 1 : (long)(blockHeader >> 3);
1008+
if (isWrongBlock) {
1009+
DISPLAY("Error: unsupported block type \n");
10111010
detectError = 1;
10121011
break;
1013-
} }
1012+
}
1013+
lastBlock = blockHeader & 1;
1014+
{ int const ret = fseek(srcFile, blockSize, SEEK_CUR);
1015+
if (ret != 0) {
1016+
DISPLAY("Error: could not skip to end of block\n");
1017+
detectError = 1;
1018+
break;
1019+
} } }
10141020
} while (lastBlock != 1);
10151021

10161022
if (detectError) break;

0 commit comments

Comments
 (0)