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

Update RAR5 code to report encryption #2096

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

dunhor
Copy link
Contributor

@dunhor dunhor commented Mar 24, 2024

Currently, the RAR5 code always reports ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED for archive_read_has_encrypted_entries, nor does it set any of the entry-specific properties, even though it has enough information to properly report this information. Accurate reporting of encryption is super useful for applications because reporting an error message such as "the archive is encrypted, but we don't currently support encryption" is a lot better than a not generally useful errno value and a non-localizable error string with a confusing and unpredictable error message.

Fixes #1661

/* fallthrough */
case EX_SUBDATA:
/* fallthrough */
default:
/* Skip unsupported entry. */
return consume(a, extra_data_size);
extra_data_size -= extra_field_size;
if (ARCHIVE_OK != consume(a, extra_field_size)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't actually encounter any errors specific to this code-path, however it made me felt uneasy - e.g. skipping an earlier unsupported field may cause us to skip identifying an encryption field.

Comment on lines +2432 to +2434
if (rar->has_encrypted_entries == ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW) {
rar->has_encrypted_entries = 0;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something I didn't necessarily like doing, but I copied from other places. Encryption might not necessarily be detected when reading the first header (e.g. if the Nth entry is the first encrypted one), however there's not much difference in practice between perpetually returning ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW and returning 0.

Comment on lines +143 to +151
DEFINE_TEST(test_read_format_rar4_solid_encrypted)
{
/* TODO: If solid RAR4 support is ever added, the following should pass */
#if 0
test_encrypted_rar_archive("test_read_format_rar4_solid_encrypted.rar", 0, 1);
#else
skipping("RAR4 solid archive support not currently available");
#endif
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figure that at least having this here will make someone's life easier if RAR4 solid support is ever added. I can remove if folks don't want currently dead code laying around.

Comment on lines +74 to +78
#ifdef HAVE_ZLIB_H
int zip_version = 20;
#else
int zip_version = 10;
#endif
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something I hit running the tests locally. I should probably look into how to ensure that I build with zlib, but this can otherwise alleviate pain for anyone else who runs into this.

dunhor and others added 2 commits April 2, 2024 00:12
@dunhor
Copy link
Contributor Author

dunhor commented Apr 4, 2024

Fixes #1661

Edit - oops, I need this in the description

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.

Unhelpful error when extracting encrypted data only RAR
1 participant