aboutsummaryrefslogtreecommitdiff
path: root/libarchive/archive_read_support_format_rar5.c
diff options
context:
space:
mode:
Diffstat (limited to 'libarchive/archive_read_support_format_rar5.c')
-rw-r--r--libarchive/archive_read_support_format_rar5.c66
1 files changed, 57 insertions, 9 deletions
diff --git a/libarchive/archive_read_support_format_rar5.c b/libarchive/archive_read_support_format_rar5.c
index 48dde0c2e814..17e501e02e9f 100644
--- a/libarchive/archive_read_support_format_rar5.c
+++ b/libarchive/archive_read_support_format_rar5.c
@@ -1619,10 +1619,13 @@ static int process_head_file_extra(struct archive_read* a,
{
uint64_t extra_field_size;
uint64_t extra_field_id = 0;
- int ret = ARCHIVE_FATAL;
uint64_t var_size;
while(extra_data_size > 0) {
+ /* Make sure we won't fail if the file declares only unsupported
+ attributes. */
+ int ret = ARCHIVE_OK;
+
if(!read_var(a, &extra_field_size, &var_size))
return ARCHIVE_EOF;
@@ -1675,12 +1678,53 @@ static int process_head_file_extra(struct archive_read* a,
if (ARCHIVE_OK != consume(a, extra_field_size)) {
return ARCHIVE_EOF;
}
+
+ /* Don't fail on unsupported attribute -- we've handled it
+ by skipping over it. */
+ ret = ARCHIVE_OK;
+ }
+
+ if (ret != ARCHIVE_OK) {
+ /* Forward any errors signalled by the attribute parsing
+ functions. */
+ return ret;
}
}
- if(ret != ARCHIVE_OK) {
- /* Attribute not implemented. */
- return ret;
+ if (extra_data_size != 0) {
+ /* We didn't skip everything, or we skipped too much; either way,
+ there's an error in this parsing function. */
+
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_PROGRAMMER,
+ "unsupported structure of file header extra data");
+ return ARCHIVE_FATAL;
+ }
+
+ return ARCHIVE_OK;
+}
+
+static int file_entry_sanity_checks(struct archive_read* a,
+ size_t block_flags, uint8_t is_dir, uint64_t unpacked_size,
+ size_t packed_size)
+{
+ if (is_dir) {
+ const int declares_data_size =
+ (int) (unpacked_size != 0 || packed_size != 0);
+
+ /* FILE entries for directories still declare HFL_DATA in block flags,
+ even though attaching data to such blocks doesn't make much sense. */
+ if (declares_data_size) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "directory entries cannot have any data");
+ return ARCHIVE_FATAL;
+ }
+ } else {
+ const int declares_hfl_data = (int) ((block_flags & HFL_DATA) != 0);
+ if (!declares_hfl_data) {
+ archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
+ "no data found in file/service block");
+ return ARCHIVE_FATAL;
+ }
}
return ARCHIVE_OK;
@@ -1701,6 +1745,7 @@ static int process_head_file(struct archive_read* a, struct rar5* rar,
int c_method = 0, c_version = 0;
char name_utf8_buf[MAX_NAME_IN_BYTES];
const uint8_t* p;
+ int sanity_ret;
enum FILE_FLAGS {
DIRECTORY = 0x0001, UTIME = 0x0002, CRC32 = 0x0004,
@@ -1744,10 +1789,6 @@ static int process_head_file(struct archive_read* a, struct rar5* rar,
rar->file.bytes_remaining = data_size;
} else {
rar->file.bytes_remaining = 0;
-
- archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
- "no data found in file/service block");
- return ARCHIVE_FATAL;
}
if(!read_var_sized(a, &file_flags, NULL))
@@ -1764,6 +1805,13 @@ static int process_head_file(struct archive_read* a, struct rar5* rar,
rar->file.dir = (uint8_t) ((file_flags & DIRECTORY) > 0);
+ sanity_ret = file_entry_sanity_checks(a, block_flags, rar->file.dir,
+ unpacked_size, data_size);
+
+ if (sanity_ret != ARCHIVE_OK) {
+ return sanity_ret;
+ }
+
if(!read_var_sized(a, &file_attr, NULL))
return ARCHIVE_EOF;
@@ -4163,7 +4211,7 @@ static int rar5_read_data(struct archive_read *a, const void **buff,
* it's impossible to perform any decompression. */
archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT,
"Can't decompress an entry marked as a directory");
- return ARCHIVE_FAILED;
+ return ARCHIVE_FATAL;
}
if(!rar->skip_mode && (rar->cstate.last_write_ptr > rar->file.unpacked_size)) {