Hi,
How should I use LZMA-SDK to unpack an XZ archive if I don't know its exact size?
For example: I scan a raw disk/memory dump, find an XZ magic, and since I don't know its size,
I try to unpack it, chunk by chunk, forward, iteratively.
The stream is unpacked successfully (CXzUnpacker::numFinishedStreams has been increased),
but XzUnpacker_IsStreamWasFinished() returns FALSE because it is already expecting padding nulls,
and exactly x4 zeros, otherwise unpacking error.
BUT there is some garbage after the XZ stream!
How to handle this without falling to a low level like manual block parsing?
At the moment I had to modify LZMA-SDK
I added int singleStreamOnly to CXzUnpacker and hacked the exit from the unpacking loop.
at the end of case XZ_STATE_STREAM_FOOTER:
if (!Xz_CheckFooter(p->streamFlags, p->indexSize, p->buf))
return SZ_ERROR_CRC;
// HACK: don't process potential padding and following streams
if (p->singleStreamOnly)
{
*status = CODER_STATUS_FINISHED_WITH_MARK;
return SZ_OK;
}
}
break;
This solved my problem.
Moreover, it did not break the original logic - the decoder remained in the correct state,
and the next call will continue parsing the potential padding and the next stream.
But carrying a modified version of LZMA-ZDK is not very good idea,
maybe there is a better solution?
These cases are complicated.
I don't remember details.