git-svn: trunk@2293
Trog authored on 2006/09/20 19:28:49... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Wed Sep 20 11:26:11 BST 2006 (trog) |
|
2 |
+----------------------------------- |
|
3 |
+ *libclamav/unrar/unrar.c, unrar.h, unrarppm.c, unrarvm.c: Update to align |
|
4 |
+ with current RAR version. |
|
5 |
+ |
|
1 | 6 |
Wed Sep 20 11:22:56 BST 2006 (njh) |
2 | 7 |
---------------------------------- |
3 | 8 |
* libclamav: Removed some multiple calls to blobClose() and added one |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
/* |
2 | 2 |
* Extract RAR archives |
3 | 3 |
* |
4 |
- * Copyright (C) 2005 trog@uncon.org |
|
4 |
+ * Copyright (C) 2005-2006 trog@uncon.org |
|
5 | 5 |
* |
6 | 6 |
* This code is based on the work of Alexander L. Roshal |
7 | 7 |
* |
... | ... |
@@ -237,6 +237,8 @@ static void copy_string(unpack_data_t *unpack_data, unsigned int length, unsigne |
237 | 237 |
|
238 | 238 |
static void *read_header(int fd, header_type hdr_type) |
239 | 239 |
{ |
240 |
+ uint8_t encrypt_ver; |
|
241 |
+ |
|
240 | 242 |
switch(hdr_type) { |
241 | 243 |
case MAIN_HEAD: { |
242 | 244 |
main_header_t *main_hdr; |
... | ... |
@@ -252,6 +254,14 @@ static void *read_header(int fd, header_type hdr_type) |
252 | 252 |
main_hdr->flags = rar_endian_convert_16(main_hdr->flags); |
253 | 253 |
main_hdr->head_size = rar_endian_convert_16(main_hdr->head_size); |
254 | 254 |
main_hdr->head_crc = rar_endian_convert_16(main_hdr->head_crc); |
255 |
+ if (main_hdr->flags & MHD_ENCRYPTVER) { |
|
256 |
+ cli_dbgmsg("RAR Encrypt version: %d\n", encrypt_ver); |
|
257 |
+ if (cli_readn(fd, &encrypt_ver, sizeof(uint8_t)) != sizeof(uint8_t)) { |
|
258 |
+ free(main_hdr); |
|
259 |
+ return NULL; |
|
260 |
+ } |
|
261 |
+ } |
|
262 |
+ |
|
255 | 263 |
return main_hdr; |
256 | 264 |
} |
257 | 265 |
case FILE_HEAD: { |
... | ... |
@@ -504,7 +514,8 @@ static void unp_write_buf(unpack_data_t *unpack_data) |
504 | 504 |
next_filter = unpack_data->PrgStack.array[i+1]; |
505 | 505 |
if (next_filter==NULL || |
506 | 506 |
next_filter->block_start!=block_start || |
507 |
- next_filter->block_length!=filtered_size) { |
|
507 |
+ next_filter->block_length!=filtered_size || |
|
508 |
+ next_filter->next_window) { |
|
508 | 509 |
break; |
509 | 510 |
} |
510 | 511 |
rarvm_set_memory(&unpack_data->rarvm_data, 0, |
... | ... |
@@ -1355,7 +1366,7 @@ rar_metadata_t *cli_unrar(int fd, const char *dirname, const struct cl_limits *l |
1355 | 1355 |
unsigned char filename[1024]; |
1356 | 1356 |
unpack_data_t *unpack_data; |
1357 | 1357 |
rar_metadata_t *metadata=NULL, *metadata_tail=NULL, *new_metadata; |
1358 |
- |
|
1358 |
+ |
|
1359 | 1359 |
cli_dbgmsg("in cli_unrar\n"); |
1360 | 1360 |
if (!is_rar_archive(fd)) { |
1361 | 1361 |
return FALSE; |
... | ... |
@@ -1370,7 +1381,7 @@ rar_metadata_t *cli_unrar(int fd, const char *dirname, const struct cl_limits *l |
1370 | 1370 |
unpack_data->PrgStack.array = unpack_data->Filters.array = NULL; |
1371 | 1371 |
unpack_data->PrgStack.num_items = unpack_data->Filters.num_items = 0; |
1372 | 1372 |
unpack_data->unp_crc = 0xffffffff; |
1373 |
- |
|
1373 |
+ |
|
1374 | 1374 |
/* unpack_init_data(FALSE, unpack_data); */ |
1375 | 1375 |
ppm_constructor(&unpack_data->ppm_data); |
1376 | 1376 |
|
... | ... |
@@ -1456,7 +1467,7 @@ rar_metadata_t *cli_unrar(int fd, const char *dirname, const struct cl_limits *l |
1456 | 1456 |
if (file_header->flags & LHD_PASSWORD) { |
1457 | 1457 |
cli_dbgmsg("PASSWORDed file: %s\n", file_header->filename); |
1458 | 1458 |
metadata_tail->encrypted = TRUE; |
1459 |
- } else if (file_header->unpack_size) { |
|
1459 |
+ } else /*if (file_header->unpack_size)*/ { |
|
1460 | 1460 |
snprintf(filename, 1024, "%s/%lu.ura", dirname, file_count); |
1461 | 1461 |
ofd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0600); |
1462 | 1462 |
if (ofd < 0) { |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
/* |
2 | 2 |
* Extract RAR archives |
3 | 3 |
* |
4 |
- * Copyright (C) 2005 trog@uncon.org |
|
4 |
+ * Copyright (C) 2005-2006 trog@uncon.org |
|
5 | 5 |
* |
6 | 6 |
* This code is based on the work of Alexander L. Roshal |
7 | 7 |
* |
... | ... |
@@ -71,31 +71,32 @@ typedef struct rar_metadata_tag |
71 | 71 |
#define SIZEOF_BEEAHEAD 24 |
72 | 72 |
#define SIZEOF_STREAMHEAD 26 |
73 | 73 |
|
74 |
-#define MHD_VOLUME 0x0001 |
|
75 |
-#define MHD_COMMENT 0x0002 |
|
76 |
-#define MHD_LOCK 0x0004 |
|
77 |
-#define MHD_SOLID 0x0008 |
|
78 |
-#define MHD_PACK_COMMENT 0x0010 |
|
79 |
-#define MHD_NEWNUMBERING 0x0010 |
|
80 |
-#define MHD_AV 0x0020 |
|
81 |
-#define MHD_PROTECT 0x0040 |
|
82 |
-#define MHD_PASSWORD 0x0080 |
|
83 |
-#define MHD_FIRSTVOLUME 0x0100 |
|
74 |
+#define MHD_VOLUME 0x0001 |
|
75 |
+#define MHD_COMMENT 0x0002 |
|
76 |
+#define MHD_LOCK 0x0004 |
|
77 |
+#define MHD_SOLID 0x0008 |
|
78 |
+#define MHD_PACK_COMMENT 0x0010 |
|
79 |
+#define MHD_NEWNUMBERING 0x0010 |
|
80 |
+#define MHD_AV 0x0020 |
|
81 |
+#define MHD_PROTECT 0x0040 |
|
82 |
+#define MHD_PASSWORD 0x0080 |
|
83 |
+#define MHD_FIRSTVOLUME 0x0100 |
|
84 |
+#define MHD_ENCRYPTVER 0x0200 |
|
84 | 85 |
|
85 |
-#define LHD_SPLIT_BEFORE 0x0001 |
|
86 |
-#define LHD_SPLIT_AFTER 0x0002 |
|
87 |
-#define LHD_PASSWORD 0x0004 |
|
88 |
-#define LHD_COMMENT 0x0008 |
|
89 |
-#define LHD_SOLID 0x0010 |
|
86 |
+#define LHD_SPLIT_BEFORE 0x0001 |
|
87 |
+#define LHD_SPLIT_AFTER 0x0002 |
|
88 |
+#define LHD_PASSWORD 0x0004 |
|
89 |
+#define LHD_COMMENT 0x0008 |
|
90 |
+#define LHD_SOLID 0x0010 |
|
90 | 91 |
|
91 |
-#define LONG_BLOCK 0x8000 |
|
92 |
+#define LONG_BLOCK 0x8000 |
|
92 | 93 |
|
93 |
-#define NC 299 /* alphabet = {0, 1, 2, ..., NC - 1} */ |
|
94 |
-#define DC 60 |
|
95 |
-#define RC 28 |
|
96 |
-#define LDC 17 |
|
97 |
-#define BC 20 |
|
98 |
-#define HUFF_TABLE_SIZE (NC+DC+RC+LDC) |
|
94 |
+#define NC 299 /* alphabet = {0, 1, 2, ..., NC - 1} */ |
|
95 |
+#define DC 60 |
|
96 |
+#define RC 28 |
|
97 |
+#define LDC 17 |
|
98 |
+#define BC 20 |
|
99 |
+#define HUFF_TABLE_SIZE (NC+DC+RC+LDC) |
|
99 | 100 |
|
100 | 101 |
#define MAX_BUF_SIZE 32768 |
101 | 102 |
#define MAXWINSIZE 0x400000 |
... | ... |
@@ -113,8 +114,8 @@ typedef struct main_header_tag |
113 | 113 |
uint8_t head_type __attribute__ ((packed)); |
114 | 114 |
uint16_t flags __attribute__ ((packed)); |
115 | 115 |
uint16_t head_size __attribute__ ((packed)); |
116 |
- uint16_t reserved __attribute__ ((packed)); |
|
117 |
- uint32_t reserved1 __attribute__ ((packed)); |
|
116 |
+ uint16_t highposav __attribute__ ((packed)); |
|
117 |
+ uint32_t posav __attribute__ ((packed)); |
|
118 | 118 |
} main_header_t; |
119 | 119 |
|
120 | 120 |
typedef struct file_header_tag |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
/* |
2 | 2 |
* Extract RAR archives |
3 | 3 |
* |
4 |
- * Copyright (C) 2005 trog@uncon.org |
|
4 |
+ * Copyright (C) 2005-2006 trog@uncon.org |
|
5 | 5 |
* |
6 | 6 |
* This code is based on the work of Alexander L. Roshal |
7 | 7 |
* |
... | ... |
@@ -39,14 +39,15 @@ static void cli_dbgmsg(){}; |
39 | 39 |
static void rar_dbgmsg(){}; |
40 | 40 |
#endif |
41 | 41 |
|
42 |
-const unsigned int UNIT_SIZE=sizeof(struct ppm_context); |
|
42 |
+#define MAX(a,b) (((a) > (b)) ? (a) : (b)) |
|
43 |
+ |
|
44 |
+const unsigned int UNIT_SIZE=MAX(sizeof(struct ppm_context), sizeof(struct rar_mem_blk_tag)); |
|
43 | 45 |
const unsigned int FIXED_UNIT_SIZE=12; |
44 | 46 |
const int INT_BITS=7, PERIOD_BITS=7, TOT_BITS=14, MAX_O=64; |
45 | 47 |
const int INTERVAL=1 << 7, BIN_SCALE=1 << 14, MAX_FREQ=124; |
46 | 48 |
const unsigned int TOP=1 << 24, BOT=1 << 15; |
47 | 49 |
|
48 | 50 |
/************* Start of Allocator code block ********************/ |
49 |
- |
|
50 | 51 |
static void sub_allocator_init(sub_allocator_t *sub_alloc) |
51 | 52 |
{ |
52 | 53 |
sub_alloc->sub_allocator_size = 0; |
... | ... |
@@ -72,6 +73,11 @@ static int sub_allocator_u2b(int nu) |
72 | 72 |
return UNIT_SIZE*nu; |
73 | 73 |
} |
74 | 74 |
|
75 |
+static rar_mem_blk_t* sub_allocator_mbptr(rar_mem_blk_t* base_ptr, int items) |
|
76 |
+{ |
|
77 |
+ return ((rar_mem_blk_t*) (((unsigned char *)(base_ptr)) + sub_allocator_u2b(items) )); |
|
78 |
+} |
|
79 |
+ |
|
75 | 80 |
static void sub_allocator_split_block(sub_allocator_t *sub_alloc, void *pv, |
76 | 81 |
int old_indx, int new_indx) |
77 | 82 |
{ |
... | ... |
@@ -186,19 +192,20 @@ static void sub_allocator_glue_free_blocks(sub_allocator_t *sub_alloc) |
186 | 186 |
} |
187 | 187 |
|
188 | 188 |
for (p=s0.next ; p != &s0 ; p=p->next) { |
189 |
- while ((p1 = p+p->nu)->stamp == 0xFFFF && ((int)p->nu)+p1->nu < 0x10000) { |
|
189 |
+ while ((p1 = sub_allocator_mbptr(p,p->nu))->stamp == 0xFFFF && |
|
190 |
+ ((int)p->nu)+p1->nu < 0x10000) { |
|
190 | 191 |
rar_mem_blk_remove(p1); |
191 | 192 |
p->nu += p1->nu; |
192 | 193 |
} |
193 | 194 |
} |
194 | 195 |
|
195 | 196 |
while ((p=s0.next) != &s0) { |
196 |
- for (rar_mem_blk_remove(p), sz=p->nu; sz > 128; sz-=128, p+=128) { |
|
197 |
+ for (rar_mem_blk_remove(p), sz=p->nu; sz > 128; sz-=128, p=sub_allocator_mbptr(p, 128)) { |
|
197 | 198 |
sub_allocator_insert_node(sub_alloc, p, N_INDEXES-1); |
198 | 199 |
} |
199 | 200 |
if (sub_alloc->indx2units[i=sub_alloc->units2indx[sz-1]] != sz) { |
200 | 201 |
k = sz-sub_alloc->indx2units[--i]; |
201 |
- sub_allocator_insert_node(sub_alloc, p+(sz-k), k-1); |
|
202 |
+ sub_allocator_insert_node(sub_alloc, sub_allocator_mbptr(p,sz-k), k-1); |
|
202 | 203 |
} |
203 | 204 |
sub_allocator_insert_node(sub_alloc, p, i); |
204 | 205 |
} |
... | ... |
@@ -969,6 +976,10 @@ int ppm_decode_char(ppm_data_t *ppm_data, int fd, unpack_data_t *unpack_data) |
969 | 969 |
return -1; |
970 | 970 |
} |
971 | 971 |
if (ppm_data->min_context->num_stats != 1) { |
972 |
+ if (ppm_data->min_context->con_ut.u.stats <= ppm_data->sub_alloc.ptext || |
|
973 |
+ ppm_data->min_context->con_ut.u.stats > ppm_data->sub_alloc.heap_end) { |
|
974 |
+ return -1; |
|
975 |
+ } |
|
972 | 976 |
if (!ppm_decode_symbol1(ppm_data, ppm_data->min_context)) { |
973 | 977 |
return -1; |
974 | 978 |
} |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
/* |
2 | 2 |
* Extract RAR archives |
3 | 3 |
* |
4 |
- * Copyright (C) 2005 trog@uncon.org |
|
4 |
+ * Copyright (C) 2005-2006 trog@uncon.org |
|
5 | 5 |
* |
6 | 6 |
* This code is based on the work of Alexander L. Roshal |
7 | 7 |
* |
... | ... |
@@ -1067,6 +1067,7 @@ int rarvm_prepare(rarvm_data_t *rarvm_data, rarvm_input_t *rarvm_input, unsigned |
1067 | 1067 |
cur_cmd->op1.data = filter_type; |
1068 | 1068 |
cur_cmd->op1.addr = &cur_cmd->op1.data; |
1069 | 1069 |
cur_cmd->op2.addr = &cur_cmd->op2.data; |
1070 |
+ cur_cmd->op1.type = cur_cmd->op2.type = VM_OPNONE; |
|
1070 | 1071 |
code_size = 0; |
1071 | 1072 |
} |
1072 | 1073 |
|
... | ... |
@@ -1153,6 +1154,7 @@ int rarvm_prepare(rarvm_data_t *rarvm_data, rarvm_input_t *rarvm_input, unsigned |
1153 | 1153 |
cur_cmd->op_code = VM_RET; |
1154 | 1154 |
cur_cmd->op1.addr = &cur_cmd->op1.data; |
1155 | 1155 |
cur_cmd->op2.addr = &cur_cmd->op2.data; |
1156 |
+ cur_cmd->op1.type = cur_cmd->op2.type = VM_OPNONE; |
|
1156 | 1157 |
|
1157 | 1158 |
for (i=0 ; i < prg->cmd_count ; i++) { |
1158 | 1159 |
cmd = &prg->cmd.array[i]; |