git-svn: trunk@3585
Török Edvin authored on 2008/02/06 03:25:22... | ... |
@@ -1,3 +1,11 @@ |
1 |
+Tue Feb 5 20:06:28 EET 2008 (edwin) |
|
2 |
+------------------------------------ |
|
3 |
+ * libclamav/lzma_iface.[ch], nsis/nulsft.c: |
|
4 |
+ * don't include both zlib and LzmaTypes.h (bb #805) |
|
5 |
+ * fixes build failure with non-system zlib |
|
6 |
+ * move declaration of CLI_LZMA into lzma_iface.c |
|
7 |
+ * allocate CLI_LZMA* in lzma_iface.c |
|
8 |
+ |
|
1 | 9 |
Mon Feb 4 23:20:12 EET 2008 (edwin) |
2 | 10 |
------------------------------------ |
3 | 11 |
* libclamav/scanners, filetypes, dconf: |
... | ... |
@@ -21,10 +21,35 @@ |
21 | 21 |
|
22 | 22 |
|
23 | 23 |
#include "lzma_iface.h" |
24 |
+#include "LzmaStateDecode.h" |
|
24 | 25 |
#include "cltypes.h" |
26 |
+ |
|
27 |
+/* we don't need zlib, and zlib defines Byte, that lzma also defines. |
|
28 |
+ * Enabling prefixes for zlib types avoids problems, and since |
|
29 |
+ * we don't call any zlib functions here avoids unresolved symbols too */ |
|
30 |
+#define Z_PREFIX |
|
25 | 31 |
#include "others.h" |
26 | 32 |
|
27 |
-int cli_LzmaInit(CLI_LZMA *L, uint64_t size_override) { |
|
33 |
+struct CLI_LZMA_tag { |
|
34 |
+ CLzmaDecoderState state; |
|
35 |
+ unsigned char *next_in; |
|
36 |
+ SizeT avail_in; |
|
37 |
+ unsigned char *next_out; |
|
38 |
+ SizeT avail_out; |
|
39 |
+ int initted; |
|
40 |
+ uint64_t usize; |
|
41 |
+}; |
|
42 |
+ |
|
43 |
+int cli_LzmaInit(CLI_LZMA **Lp, uint64_t size_override) { |
|
44 |
+ CLI_LZMA *L = *Lp; |
|
45 |
+ |
|
46 |
+ if(!L) { |
|
47 |
+ *Lp = L = cli_calloc(sizeof(*L), 1); |
|
48 |
+ if(!L) { |
|
49 |
+ return CL_EMEM; |
|
50 |
+ } |
|
51 |
+ } |
|
52 |
+ |
|
28 | 53 |
L->initted = 0; |
29 | 54 |
if(size_override) L->usize=size_override; |
30 | 55 |
|
... | ... |
@@ -55,19 +80,38 @@ int cli_LzmaInit(CLI_LZMA *L, uint64_t size_override) { |
55 | 55 |
return LZMA_RESULT_OK; |
56 | 56 |
} |
57 | 57 |
|
58 |
-void cli_LzmaShutdown(CLI_LZMA *L) { |
|
59 |
- if(!L->initted) return; |
|
60 |
- if(L->state.Probs) free(L->state.Probs); |
|
61 |
- if(L->state.Dictionary) free(L->state.Dictionary); |
|
58 |
+void cli_LzmaShutdown(CLI_LZMA **Lp) { |
|
59 |
+ CLI_LZMA *L; |
|
60 |
+ |
|
61 |
+ if(!Lp) return; |
|
62 |
+ L = *Lp; |
|
63 |
+ if(L->initted) { |
|
64 |
+ if(L->state.Probs) free(L->state.Probs); |
|
65 |
+ if(L->state.Dictionary) free(L->state.Dictionary); |
|
66 |
+ } |
|
67 |
+ free(L); |
|
68 |
+ *Lp = NULL; |
|
62 | 69 |
return; |
63 | 70 |
} |
64 | 71 |
|
65 |
-int cli_LzmaDecode(CLI_LZMA *L) { |
|
72 |
+int cli_LzmaDecode(CLI_LZMA **Lp, struct stream_state* state) { |
|
66 | 73 |
int res; |
67 | 74 |
SizeT processed_in, processed_out; |
75 |
+ CLI_LZMA* L = *Lp; |
|
76 |
+ |
|
77 |
+ if(L) { |
|
78 |
+ L->avail_in = state->avail_in; |
|
79 |
+ L->next_in = state->next_in; |
|
80 |
+ L->avail_out = state->avail_out; |
|
81 |
+ L->next_out = state->next_out; |
|
82 |
+ } |
|
83 |
+ |
|
84 |
+ if (!L || !L->initted) { |
|
85 |
+ if(cli_LzmaInit(Lp, 0) != LZMA_RESULT_OK) |
|
86 |
+ return LZMA_RESULT_DATA_ERROR; |
|
87 |
+ L = *Lp; |
|
88 |
+ } |
|
68 | 89 |
|
69 |
- if (!L->initted && cli_LzmaInit(L, 0) != LZMA_RESULT_OK) |
|
70 |
- return LZMA_RESULT_DATA_ERROR; |
|
71 | 90 |
|
72 | 91 |
res = LzmaDecode(&L->state, L->next_in, L->avail_in, &processed_in, L->next_out, L->avail_out, &processed_out, (L->avail_in==0)); |
73 | 92 |
|
... | ... |
@@ -76,5 +120,10 @@ int cli_LzmaDecode(CLI_LZMA *L) { |
76 | 76 |
L->next_out += processed_out; |
77 | 77 |
L->avail_out -= processed_out; |
78 | 78 |
|
79 |
+ state->avail_in = L->avail_in; |
|
80 |
+ state->next_in = L->next_in; |
|
81 |
+ state->avail_out = L->avail_out; |
|
82 |
+ state->next_out = L->next_out; |
|
83 |
+ |
|
79 | 84 |
return res; |
80 | 85 |
} |
... | ... |
@@ -22,23 +22,22 @@ |
22 | 22 |
#ifndef __LZMA_IFACE_H |
23 | 23 |
#define __LZMA_IFACE_H |
24 | 24 |
|
25 |
- |
|
26 |
-#include "LzmaStateDecode.h" |
|
27 | 25 |
#include "cltypes.h" |
28 | 26 |
|
29 |
-typedef struct { |
|
30 |
- CLzmaDecoderState state; |
|
31 |
- const unsigned char *next_in; |
|
32 |
- SizeT avail_in; |
|
33 |
- unsigned char *next_out; |
|
34 |
- SizeT avail_out; |
|
35 |
- int initted; |
|
36 |
- uint64_t usize; |
|
37 |
-} CLI_LZMA; |
|
27 |
+typedef struct CLI_LZMA_tag CLI_LZMA; |
|
28 |
+ |
|
29 |
+struct stream_state { |
|
30 |
+ uint32_t avail_in; |
|
31 |
+ unsigned char *next_in; |
|
32 |
+ uint32_t avail_out; |
|
33 |
+ unsigned char *next_out; |
|
34 |
+}; |
|
38 | 35 |
|
39 |
-int cli_LzmaInit(CLI_LZMA *, uint64_t); |
|
40 |
-void cli_LzmaShutdown(CLI_LZMA *); |
|
41 |
-int cli_LzmaDecode(CLI_LZMA *); |
|
36 |
+int cli_LzmaInit(CLI_LZMA **, uint64_t); |
|
37 |
+void cli_LzmaShutdown(CLI_LZMA **); |
|
38 |
+int cli_LzmaDecode(CLI_LZMA **, struct stream_state*); |
|
42 | 39 |
|
43 | 40 |
#define LZMA_STREAM_END 2 |
41 |
+#define LZMA_RESULT_OK 0 |
|
42 |
+#define LZMA_RESULT_DATA_ERROR 1 |
|
44 | 43 |
#endif /* __LZMA_IFACE_H */ |
... | ... |
@@ -71,14 +71,9 @@ struct nsis_st { |
71 | 71 |
uint8_t solid; |
72 | 72 |
uint8_t freecomp; |
73 | 73 |
uint8_t eof; |
74 |
- struct { |
|
75 |
- uint32_t avail_in; |
|
76 |
- unsigned char *next_in; |
|
77 |
- uint32_t avail_out; |
|
78 |
- unsigned char *next_out; |
|
79 |
- } nsis; |
|
74 |
+ struct stream_state nsis; |
|
80 | 75 |
nsis_bzstream bz; |
81 |
- CLI_LZMA lz; |
|
76 |
+ CLI_LZMA* lz; |
|
82 | 77 |
z_stream z; |
83 | 78 |
unsigned char *freeme; |
84 | 79 |
char ofn[1024]; |
... | ... |
@@ -98,7 +93,6 @@ static int nsis_init(struct nsis_st *n) { |
98 | 98 |
n->freecomp=1; |
99 | 99 |
break; |
100 | 100 |
case COMP_LZMA: |
101 |
- memset(&n->lz, 0, sizeof(CLI_LZMA)); |
|
102 | 101 |
cli_LzmaInit(&n->lz, 0xffffffffffffffffULL); |
103 | 102 |
n->freecomp=1; |
104 | 103 |
break; |
... | ... |
@@ -150,21 +144,13 @@ static int nsis_decomp(struct nsis_st *n) { |
150 | 150 |
n->nsis.next_out = n->bz.next_out; |
151 | 151 |
break; |
152 | 152 |
case COMP_LZMA: |
153 |
- n->lz.avail_in = n->nsis.avail_in; |
|
154 |
- n->lz.next_in = n->nsis.next_in; |
|
155 |
- n->lz.avail_out = n->nsis.avail_out; |
|
156 |
- n->lz.next_out = n->nsis.next_out; |
|
157 |
- switch (cli_LzmaDecode(&n->lz)) { |
|
153 |
+ switch (cli_LzmaDecode(&n->lz, &n->nsis)) { |
|
158 | 154 |
case LZMA_RESULT_OK: |
159 | 155 |
ret = CL_SUCCESS; |
160 | 156 |
break; |
161 | 157 |
case LZMA_STREAM_END: |
162 | 158 |
ret = CL_BREAK; |
163 | 159 |
} |
164 |
- n->nsis.avail_in = n->lz.avail_in; |
|
165 |
- n->nsis.next_in = n->lz.next_in; |
|
166 |
- n->nsis.avail_out = n->lz.avail_out; |
|
167 |
- n->nsis.next_out = n->lz.next_out; |
|
168 | 160 |
break; |
169 | 161 |
case COMP_ZLIB: |
170 | 162 |
n->z.avail_in = n->nsis.avail_in; |