From 88d2f72df97c95ef61ede9d620cabe49afb4c968 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 18 Aug 2017 16:18:20 -0700 Subject: [PATCH] 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. --- programs/fileio.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index e6fa61f6..3db6af73 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -994,23 +994,29 @@ static int getFileInfo(fileInfo_t* info, const char* inFileName){ { int lastBlock = 0; do { BYTE blockHeaderBuffer[3]; - U32 blockHeader; - int blockSize; size_t const readBytes = fread(blockHeaderBuffer, 1, 3, srcFile); if (readBytes != 3) { DISPLAY("There was a problem reading the block header\n"); detectError = 1; break; } - blockHeader = MEM_readLE24(blockHeaderBuffer); - lastBlock = blockHeader & 1; - blockSize = blockHeader >> 3; /* Warning : does not work when block is RLE type */ - { int const ret = fseek(srcFile, blockSize, SEEK_CUR); - if (ret != 0) { - DISPLAY("Error: could not skip to end of block\n"); + { U32 const blockHeader = MEM_readLE24(blockHeaderBuffer); + U32 const blockTypeID = (blockHeader >> 1) & 3; + U32 const isRLE = (blockTypeID == 1); + U32 const isWrongBlock = (blockTypeID == 3); + long const blockSize = isRLE ? 1 : (long)(blockHeader >> 3); + if (isWrongBlock) { + DISPLAY("Error: unsupported block type \n"); detectError = 1; break; - } } + } + lastBlock = blockHeader & 1; + { int const ret = fseek(srcFile, blockSize, SEEK_CUR); + if (ret != 0) { + DISPLAY("Error: could not skip to end of block\n"); + detectError = 1; + break; + } } } } while (lastBlock != 1); if (detectError) break;