Skip to content

Fix LzxDecoder's handling of odd sized uncompressed blocks if that block is the final one#73

Merged
Olof-Lagerkvist merged 1 commit into
LTRData:LTRData.DiscUtils-initialfrom
Raphtaliyah:fix-lzx-padding-uncompressed
Jul 14, 2026
Merged

Fix LzxDecoder's handling of odd sized uncompressed blocks if that block is the final one#73
Olof-Lagerkvist merged 1 commit into
LTRData:LTRData.DiscUtils-initialfrom
Raphtaliyah:fix-lzx-padding-uncompressed

Conversation

@Raphtaliyah

Copy link
Copy Markdown

The current implementation of LzxDecoder correctly reads the padding byte to realign the stream to 16 bits in case the uncompressed block is of an odd size.

However, if that's the last block there is no next block to align it for and even Microsoft's own tool doesn't append that padding byte, causing the read attempt below it to fail for valid blocks.

if (!reader.TryReadRawByte(out _))
{
return false;
}

I couldn't find where it's documented but looking at wimlib's implementation, they only check for that padding byte in case the block wasn't the last one, matching that behaviour.

if (istream.data_bytes_left && (block_size & 1)) {
	istream.data_bytes_left--;
	istream.data++;
}

This PR adds the same fix to the DiscUtils' code which makes it correctly extract the files I encountered this issue with.

@Olof-Lagerkvist
Olof-Lagerkvist merged commit 2c3b93b into LTRData:LTRData.DiscUtils-initial Jul 14, 2026
3 checks passed
@Olof-Lagerkvist

Copy link
Copy Markdown
Member

Well spotted!

Thanks a lot for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants