From 987ce8855e71cf8809405993b3de092e0035901e Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Sun, 18 Sep 2005 02:18:10 +0000 Subject: [PATCH] Added support for "ignore LZW/II length" flag. Now at version 2.1.0. --- nufxlib-0/Archive.c | 1 + nufxlib-0/ChangeLog.txt | 5 +++++ nufxlib-0/Lzw.c | 8 ++++++-- nufxlib-0/NufxLib.h | 7 ++++--- nufxlib-0/NufxLibPriv.h | 1 + nufxlib-0/Value.c | 11 +++++++++++ 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/nufxlib-0/Archive.c b/nufxlib-0/Archive.c index 1bc5257..125651c 100644 --- a/nufxlib-0/Archive.c +++ b/nufxlib-0/Archive.c @@ -96,6 +96,7 @@ Nu_NuArchiveNew(NuArchive** ppArchive) (*ppArchive)->valStripHighASCII = false; /* bug: this can't be set by application! */ (*ppArchive)->valJunkSkipMax = kDefaultJunkSkipMax; + (*ppArchive)->valIgnoreLZW2Len = false; (*ppArchive)->messageHandlerFunc = gNuGlobalErrorMessageHandler; diff --git a/nufxlib-0/ChangeLog.txt b/nufxlib-0/ChangeLog.txt index 29aa56a..4041851 100644 --- a/nufxlib-0/ChangeLog.txt +++ b/nufxlib-0/ChangeLog.txt @@ -1,3 +1,8 @@ +2005/09/17 fadden + - Added "kNuValIgnoreLZW2Len" flag, which enables NuLib2 to handle + archives created by an unknown but badly broken program. + - Fixed build for gcc v4.0. + 2004/10/11 ***** v2.0.3 shipped ***** 2004/09/25 fadden diff --git a/nufxlib-0/Lzw.c b/nufxlib-0/Lzw.c index 2db82d2..6eccfff 100644 --- a/nufxlib-0/Lzw.c +++ b/nufxlib-0/Lzw.c @@ -1200,7 +1200,7 @@ main_loop: bail: /*DBUG_LZW(("### end of block\n"));*/ - if (inbuf != inbufend) { + if (expectedInputUsed != (unsigned int) -1 && inbuf != inbufend) { /* data was corrupted; if we keep going this will get worse */ DBUG(("--- inbuf != inbufend in ExpandLZW2 (diff=%d)\n", inbufend - inbuf)); @@ -1481,7 +1481,11 @@ Nu_ExpandLZW(NuArchive* pArchive, const NuRecord* pRecord, if (!isType2) { err = Nu_ExpandLZW1(lzwState, rleLen); } else { - if (lzwState->dataInBuffer < lzwLen) { + if (pArchive->valIgnoreLZW2Len) { + /* some badly-formed archives need this -- not sure + what's creating them, possibly a Mac program */ + lzwLen = (unsigned int) -1; + } else if (lzwState->dataInBuffer < lzwLen) { /* rare -- GSHK will do this if you don't let it finish */ err = kNuErrBufferUnderrun; Nu_ReportError(NU_BLOB, err, "not enough compressed data " diff --git a/nufxlib-0/NufxLib.h b/nufxlib-0/NufxLib.h index 69777c8..517ca69 100644 --- a/nufxlib-0/NufxLib.h +++ b/nufxlib-0/NufxLib.h @@ -32,8 +32,8 @@ extern "C" { * fixes. */ #define kNuVersionMajor 2 -#define kNuVersionMinor 0 -#define kNuVersionBug 3 +#define kNuVersionMinor 1 +#define kNuVersionBug 0 /* @@ -269,7 +269,8 @@ typedef enum NuValueID { kNuValueMimicSHK = 10, kNuValueMaskDataless = 11, kNuValueStripHighASCII = 12, - kNuValueJunkSkipMax = 13 + kNuValueJunkSkipMax = 13, + kNuValueIgnoreLZW2Len = 14 } NuValueID; typedef unsigned long NuValue; diff --git a/nufxlib-0/NufxLibPriv.h b/nufxlib-0/NufxLibPriv.h index b3f7d4a..349b45e 100644 --- a/nufxlib-0/NufxLibPriv.h +++ b/nufxlib-0/NufxLibPriv.h @@ -156,6 +156,7 @@ struct NuArchive { NuValue valOnlyUpdateOlder; /* modify original arc in place? */ NuValue valStripHighASCII; /* during EOL conv, strip hi bit? */ NuValue valJunkSkipMax; /* scan this far for header */ + NuValue valIgnoreLZW2Len; /* don't verify LZW/II len field */ /* callback functions */ NuCallback selectionFilterFunc; diff --git a/nufxlib-0/Value.c b/nufxlib-0/Value.c index 0f5c056..161d8a4 100644 --- a/nufxlib-0/Value.c +++ b/nufxlib-0/Value.c @@ -62,6 +62,9 @@ Nu_GetValue(NuArchive* pArchive, NuValueID ident, NuValue* pValue) case kNuValueJunkSkipMax: *pValue = pArchive->valJunkSkipMax; break; + case kNuValueIgnoreLZW2Len: + *pValue = pArchive->valIgnoreLZW2Len; + break; default: err = kNuErrInvalidArg; Nu_ReportError(NU_BLOB, err, "Unknown ValueID %d requested", ident); @@ -186,6 +189,14 @@ Nu_SetValue(NuArchive* pArchive, NuValueID ident, NuValue value) } pArchive->valJunkSkipMax = value; break; + case kNuValueIgnoreLZW2Len: + if (value != true && value != false) { + Nu_ReportError(NU_BLOB, err, + "Invalid kNuValueIgnoreLZW2Len value %ld", value); + goto bail; + } + pArchive->valIgnoreLZW2Len = value; + break; default: Nu_ReportError(NU_BLOB, err, "Unknown ValueID %d requested", ident); goto bail;