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

ZIP_CHECKCONS wrong failures with stored, encrypted entries - fix included #474

Closed
ralfjunker opened this issue Nov 27, 2024 · 1 comment
Labels
bug libzip doesn't behave as expected.

Comments

@ralfjunker
Copy link

ZIP_CHECKCONS reports wrong failures for stored, encrypted entries.

This happens because encryption adds extra bytes to the compressed size which zip_dirent_check_consistency() (GIT main at the time of this writing) does not take into account.

Here is a proposed fix:

int
zip_dirent_check_consistency(zip_dirent_t *dirent) {
    if (dirent->comp_method == ZIP_CM_STORE)
        switch (dirent->encryption_method) {
            case ZIP_EM_NONE:
                if (dirent->comp_size != dirent->uncomp_size)
                    return ZIP_ER_DETAIL_STORED_SIZE_MISMATCH;
                    break;
            case ZIP_EM_TRAD_PKWARE:
                if (dirent->comp_size != dirent->uncomp_size + 12)
                    return ZIP_ER_DETAIL_STORED_SIZE_MISMATCH;
                    break;
            case ZIP_EM_AES_128:
                if (dirent->comp_size != dirent->uncomp_size + 20)
                    return ZIP_ER_DETAIL_STORED_SIZE_MISMATCH;
                    break;
            case ZIP_EM_AES_192:
                if (dirent->comp_size != dirent->uncomp_size + 24)
                    return ZIP_ER_DETAIL_STORED_SIZE_MISMATCH;
                    break;
            case ZIP_EM_AES_256:
                if (dirent->comp_size != dirent->uncomp_size + 28)
                    return ZIP_ER_DETAIL_STORED_SIZE_MISMATCH;
                    break;
        }
    return 0;
}
@ralfjunker ralfjunker added the bug libzip doesn't behave as expected. label Nov 27, 2024
@dillof dillof closed this as completed in 3d25095 Dec 11, 2024
@dillof
Copy link
Member

dillof commented Dec 11, 2024

Applied, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug libzip doesn't behave as expected.
Projects
None yet
Development

No branches or pull requests

2 participants