There appear to be RAR5 archives out in the wild that have blocks at the
end of files that don't produce any data. The code in libarchive has an
infinite loop that won't break until it processes a block that produces
data, which will end up reading past the end of the file if the last
block in the file produces no data.
return (hdr->block_flags_u8 >> 7) & 1;
}
+static inline
+uint8_t bf_is_last_block(const struct compressed_block_header* hdr) {
+ return (hdr->block_flags_u8 >> 6) & 1;
+}
+
static inline struct rar5* get_context(struct archive_read* a) {
return (struct rar5*) a->format->data;
}
if(rar->cstate.last_write_ptr ==
rar->cstate.write_ptr) {
/* The block didn't generate any new data,
- * so just process a new block. */
+ * so just process a new block if this one
+ * wasn't the last block in the file. */
+ if (bf_is_last_block(&rar->last_block_hdr)) {
+ return ARCHIVE_EOF;
+ }
+
continue;
}