Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For mdx format, Adler-32 is computed twice for zlib decompression #1775

Open
shenlebantongying opened this issue Sep 14, 2024 · 0 comments
Open

Comments

@shenlebantongying
Copy link
Collaborator

shenlebantongying commented Sep 14, 2024

Code here can be optimized:

// zlib compression
decompressedBlock = zlibDecompress( buf, size );
if ( !checkAdler32( decompressedBlock.constData(), decompressedBlock.size(), checksum ) ) {
gdWarning( "MDict: parseCompressedBlock: zlib: checksum does not match" );
return false;
}
break;

The z_stream in zlibDecompress has a field adler

z_stream zs;

See zlib's doc's inflate

otherwise it sets strm->adler to the Adler-32 checksum of all output produced so far (that is, total_out bytes)

In other words, zlib's inflate will be rolling a alder for final checksum and there is no need to go over the decompressed data to compute it again.

@shenlebantongying shenlebantongying added good first issue Good for newcomers and removed good first issue Good for newcomers labels Sep 14, 2024
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

No branches or pull requests

1 participant