~ubuntu-branches/ubuntu/wily/clamav/wily-proposed

« back to all changes in this revision

Viewing changes to .pc/0005-libclamav-use-libmspack.patch/libclamav/mspack.h

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Sebastian Andrzej Siewior, Andreas Cadhalpun, Scott Kitterman, Javier Fernández-Sanguino
  • Date: 2015-01-28 00:25:13 UTC
  • mfrom: (0.48.14 sid)
  • Revision ID: package-import@ubuntu.com-20150128002513-lil2oi74cooy4lzr
Tags: 0.98.6+dfsg-1
[ Sebastian Andrzej Siewior ]
* update "fix-ssize_t-size_t-off_t-printf-modifier", include of misc.h was
  missing but was pulled in via the systemd patch.
* Don't leak return codes from libmspack to clamav API. (Closes: #774686).

[ Andreas Cadhalpun ]
* Add patch to avoid emitting incremental progress messages when not
  outputting to a terminal. (Closes: #767350)
* Update lintian-overrides for unused-file-paragraph-in-dep5-copyright.
* clamav-base.postinst: always chown /var/log/clamav and /var/lib/clamav
  to clamav:clamav, not only on fresh installations. (Closes: #775400)
* Adapt the clamav-daemon and clamav-freshclam logrotate scripts,
  so that they correctly work under systemd.
* Move the PidFile variable from the clamd/freshclam configuration files
  to the init scripts. This makes the init scripts more robust against
  misconfiguration and avoids error messages with systemd. (Closes: #767353)
* debian/copyright: drop files from Files-Excluded only present in github
  tarballs
* Drop Workaround-a-bug-in-libc-on-Hurd.patch, because hurd got fixed.
  (see #752237)
* debian/rules: Remove useless --with-system-tommath --without-included-ltdl
  configure options.

[ Scott Kitterman ]
* Stop stripping llvm when repacking the tarball as the system llvm on some
  releases is too old to use
* New upstream bugfix release
  - Library shared object revisions.
  - Includes a patch from Sebastian Andrzej Siewior making ClamAV pid files
    compatible with systemd.
  - Fix a heap out of bounds condition with crafted Yoda's crypter files.
    This issue was discovered by Felix Groebert of the Google Security Team.
  - Fix a heap out of bounds condition with crafted mew packer files. This
    issue was discovered by Felix Groebert of the Google Security Team.
  - Fix a heap out of bounds condition with crafted upx packer files. This
    issue was discovered by Kevin Szkudlapski of Quarkslab.
  - Fix a heap out of bounds condition with crafted upack packer files. This
    issue was discovered by Sebastian Andrzej Siewior. CVE-2014-9328.
  - Compensate a crash due to incorrect compiler optimization when handling
    crafted petite packer files. This issue was discovered by Sebastian
    Andrzej Siewior.
* Update lintian override for embedded zlib to match new so version

[ Javier Fernández-Sanguino ]
* Updated Spanish Debconf template translation (Closes: #773563)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file includes code from libmspack adapted for libclamav by
 
3
 * tkojm@clamav.net
 
4
 *
 
5
 * Copyright (C) 2003-2004 Stuart Caie
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public
 
9
 * License version 2.1 as published by the Free Software Foundation.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 * 
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this library; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
 
19
 * USA
 
20
 */
 
21
 
 
22
#ifndef __MSPACK_H
 
23
#define __MSPACK_H
 
24
 
 
25
#include <sys/types.h>
 
26
#include "cab.h"
 
27
 
 
28
 
 
29
/***************************************************************************
 
30
 *                       MS-ZIP decompression definitions                  *
 
31
 ***************************************************************************/
 
32
 
 
33
#define MSZIP_FRAME_SIZE          (32768) /* size of LZ history window */
 
34
#define MSZIP_MAX_HUFFBITS        (16)    /* maximum huffman code length */
 
35
#define MSZIP_LITERAL_MAXSYMBOLS  (288)   /* literal/length huffman tree */
 
36
#define MSZIP_LITERAL_TABLEBITS   (9)
 
37
#define MSZIP_DISTANCE_MAXSYMBOLS (32)    /* distance huffman tree */
 
38
#define MSZIP_DISTANCE_TABLEBITS  (6)
 
39
 
 
40
/* if there are less direct lookup entries than symbols, the longer
 
41
 * code pointers will be <= maxsymbols. This must not happen, or we
 
42
 * will decode entries badly */
 
43
#if (1 << MSZIP_LITERAL_TABLEBITS) < (MSZIP_LITERAL_MAXSYMBOLS * 2)
 
44
# define MSZIP_LITERAL_TABLESIZE (MSZIP_LITERAL_MAXSYMBOLS * 4)
 
45
#else
 
46
# define MSZIP_LITERAL_TABLESIZE ((1 << MSZIP_LITERAL_TABLEBITS) + \
 
47
                                  (MSZIP_LITERAL_MAXSYMBOLS * 2))
 
48
#endif
 
49
 
 
50
#if (1 << MSZIP_DISTANCE_TABLEBITS) < (MSZIP_DISTANCE_MAXSYMBOLS * 2)
 
51
# define MSZIP_DISTANCE_TABLESIZE (MSZIP_DISTANCE_MAXSYMBOLS * 4)
 
52
#else
 
53
# define MSZIP_DISTANCE_TABLESIZE ((1 << MSZIP_DISTANCE_TABLEBITS) + \
 
54
                                  (MSZIP_DISTANCE_MAXSYMBOLS * 2))
 
55
#endif
 
56
 
 
57
struct mszip_stream {
 
58
  int ofd;                  /* output file descriptor */
 
59
 
 
60
  /* inflate() will call this whenever the window should be emptied. */
 
61
  int (*flush_window)(struct mszip_stream *, unsigned int);
 
62
 
 
63
  int error, repair_mode, bytes_output, input_end;
 
64
 
 
65
  /* I/O buffering */
 
66
  unsigned char *inbuf, *i_ptr, *i_end, *o_ptr, *o_end;
 
67
  unsigned int bit_buffer, bits_left, inbuf_size;
 
68
 
 
69
  unsigned int window_posn;             /* offset within window  */
 
70
 
 
71
  /* huffman code lengths */
 
72
  unsigned char  LITERAL_len[MSZIP_LITERAL_MAXSYMBOLS];
 
73
  unsigned char  DISTANCE_len[MSZIP_DISTANCE_MAXSYMBOLS];
 
74
 
 
75
  /* huffman decoding tables */
 
76
  unsigned short LITERAL_table [MSZIP_LITERAL_TABLESIZE];
 
77
  unsigned short DISTANCE_table[MSZIP_DISTANCE_TABLESIZE];
 
78
 
 
79
  /* 32kb history window */
 
80
  unsigned char window[MSZIP_FRAME_SIZE];
 
81
 
 
82
  /* cabinet related stuff */
 
83
  struct cab_file *file;
 
84
  int (*read_cb)(struct cab_file *, unsigned char *, int);
 
85
 
 
86
  unsigned char wflag;      /* write flag */
 
87
  unsigned int last;        /* prior end of content buffer */
 
88
 
 
89
};
 
90
 
 
91
struct mszip_stream *mszip_init(int ofd,
 
92
                                  int input_buffer_size,
 
93
                                  int repair_mode,
 
94
                                  struct cab_file *file,
 
95
                                  int (*read_cb)(struct cab_file *, unsigned char *, int));
 
96
 
 
97
extern int mszip_decompress(struct mszip_stream *zip, uint32_t out_bytes);
 
98
 
 
99
void mszip_free(struct mszip_stream *zip);
 
100
 
 
101
 
 
102
/***************************************************************************
 
103
 *                       Quantum decompression definitions                 *
 
104
 ***************************************************************************/
 
105
 
 
106
/* Quantum compression / decompression definitions */
 
107
 
 
108
#define QTM_FRAME_SIZE (32768)
 
109
 
 
110
struct qtm_modelsym {
 
111
  unsigned short sym, cumfreq;
 
112
};
 
113
 
 
114
struct qtm_model {
 
115
  int shiftsleft, entries;
 
116
  struct qtm_modelsym *syms;
 
117
};
 
118
 
 
119
struct qtm_stream {
 
120
  int ofd;                  /* output file descriptor */
 
121
 
 
122
  unsigned char *window;          /* decoding window                         */
 
123
  unsigned int window_size;       /* window size                             */
 
124
  unsigned int window_posn;       /* decompression offset within window      */
 
125
  unsigned int frame_start;       /* start of current frame within window    */
 
126
 
 
127
  unsigned short H, L, C;         /* high/low/current: arith coding state    */
 
128
  unsigned char header_read;      /* have we started decoding a new frame?   */
 
129
  unsigned char wflag;      /* write flag */
 
130
 
 
131
  int error, input_end;
 
132
 
 
133
  /* data tables */
 
134
  unsigned int  position_base[42];
 
135
  unsigned char extra_bits[42], length_base[27], length_extra[27];
 
136
 
 
137
  /* four literal models, each representing 64 symbols
 
138
   * model0 for literals from   0 to  63 (selector = 0)
 
139
   * model1 for literals from  64 to 127 (selector = 1)
 
140
   * model2 for literals from 128 to 191 (selector = 2)
 
141
   * model3 for literals from 129 to 255 (selector = 3) */
 
142
  struct qtm_model model0, model1, model2, model3;
 
143
 
 
144
  /* three match models.
 
145
   * model4 for match with fixed length of 3 bytes
 
146
   * model5 for match with fixed length of 4 bytes
 
147
   * model6 for variable length match, encoded with model6len model */
 
148
  struct qtm_model model4, model5, model6, model6len;
 
149
 
 
150
  /* selector model. 0-6 to say literal (0,1,2,3) or match (4,5,6) */
 
151
  struct qtm_model model7;
 
152
 
 
153
  /* symbol arrays for all models */
 
154
  struct qtm_modelsym m0sym[64 + 1];
 
155
  struct qtm_modelsym m1sym[64 + 1];
 
156
  struct qtm_modelsym m2sym[64 + 1];
 
157
  struct qtm_modelsym m3sym[64 + 1];
 
158
  struct qtm_modelsym m4sym[24 + 1];
 
159
  struct qtm_modelsym m5sym[36 + 1];
 
160
  struct qtm_modelsym m6sym[42 + 1], m6lsym[27 + 1];
 
161
  struct qtm_modelsym m7sym[7 + 1];
 
162
 
 
163
  /* I/O buffers - 1*/
 
164
  unsigned int  bit_buffer;
 
165
 
 
166
  /* cabinet related stuff */
 
167
  struct cab_file *file;
 
168
  int (*read_cb)(struct cab_file *, unsigned char *, int);
 
169
 
 
170
  /* I/O buffers - 2*/
 
171
  unsigned char *inbuf, *i_ptr, *i_end, *o_ptr, *o_end;
 
172
  unsigned int  inbuf_size;
 
173
  unsigned char bits_left;
 
174
 
 
175
};
 
176
 
 
177
extern struct qtm_stream *qtm_init(int ofd,
 
178
                                     int window_bits,
 
179
                                     int input_buffer_size,
 
180
                                     struct cab_file *file,
 
181
                                     int (*read_cb)(struct cab_file *, unsigned char *, int));
 
182
 
 
183
extern int qtm_decompress(struct qtm_stream *qtm, uint32_t out_bytes);
 
184
 
 
185
void qtm_free(struct qtm_stream *qtm);
 
186
 
 
187
/***************************************************************************
 
188
 *                       LZX decompression definitions                     *
 
189
 ***************************************************************************/
 
190
 
 
191
/* some constants defined by the LZX specification */
 
192
#define LZX_MIN_MATCH                (2)
 
193
#define LZX_MAX_MATCH                (257)
 
194
#define LZX_NUM_CHARS                (256)
 
195
#define LZX_BLOCKTYPE_INVALID        (0)   /* also blocktypes 4-7 invalid */
 
196
#define LZX_BLOCKTYPE_VERBATIM       (1)
 
197
#define LZX_BLOCKTYPE_ALIGNED        (2)
 
198
#define LZX_BLOCKTYPE_UNCOMPRESSED   (3)
 
199
#define LZX_PRETREE_NUM_ELEMENTS     (20)
 
200
#define LZX_ALIGNED_NUM_ELEMENTS     (8)   /* aligned offset tree #elements */
 
201
#define LZX_NUM_PRIMARY_LENGTHS      (7)   /* this one missing from spec! */
 
202
#define LZX_NUM_SECONDARY_LENGTHS    (249) /* length tree #elements */
 
203
 
 
204
/* LZX huffman defines: tweak tablebits as desired */
 
205
#define LZX_PRETREE_MAXSYMBOLS  (LZX_PRETREE_NUM_ELEMENTS)
 
206
#define LZX_PRETREE_TABLEBITS   (6)
 
207
#define LZX_MAINTREE_MAXSYMBOLS (LZX_NUM_CHARS + 50*8)
 
208
#define LZX_MAINTREE_TABLEBITS  (12)
 
209
#define LZX_LENGTH_MAXSYMBOLS   (LZX_NUM_SECONDARY_LENGTHS+1)
 
210
#define LZX_LENGTH_TABLEBITS    (12)
 
211
#define LZX_ALIGNED_MAXSYMBOLS  (LZX_ALIGNED_NUM_ELEMENTS)
 
212
#define LZX_ALIGNED_TABLEBITS   (7)
 
213
#define LZX_LENTABLE_SAFETY (64)  /* table decoding overruns are allowed */
 
214
 
 
215
#define LZX_FRAME_SIZE (32768) /* the size of a frame in LZX */
 
216
 
 
217
struct lzx_stream {
 
218
  int ofd;                        /* output file descriptor                  */
 
219
 
 
220
  off_t   offset;                 /* number of bytes actually output         */
 
221
  off_t   length;                 /* overall decompressed length of stream   */
 
222
 
 
223
  unsigned char *window;          /* decoding window                         */
 
224
  unsigned int   window_size;     /* window size                             */
 
225
  unsigned int   window_posn;     /* decompression offset within window      */
 
226
  unsigned int   frame_posn;      /* current frame offset within in window   */
 
227
  unsigned int   frame;           /* the number of 32kb frames processed     */
 
228
  unsigned int   reset_interval;  /* which frame do we reset the compressor? */
 
229
 
 
230
  unsigned int   R0, R1, R2;      /* for the LRU offset system               */
 
231
  unsigned int   block_length;    /* uncompressed length of this LZX block   */
 
232
  unsigned int   block_remaining; /* uncompressed bytes still left to decode */
 
233
 
 
234
  signed int     intel_filesize;  /* magic header value used for transform   */
 
235
  signed int     intel_curpos;    /* current offset in transform space       */
 
236
 
 
237
  unsigned char  intel_started;   /* has intel E8 decoding started?          */
 
238
  unsigned char  block_type;      /* type of the current block               */
 
239
  unsigned char  header_read;     /* have we started decoding at all yet?    */
 
240
  unsigned char  posn_slots;      /* how many posn slots in stream?          */
 
241
 
 
242
  int error;
 
243
 
 
244
  /* I/O buffering */
 
245
  unsigned char *inbuf, *i_ptr, *i_end, *o_ptr, *o_end;
 
246
  unsigned int  bit_buffer, bits_left, inbuf_size;
 
247
 
 
248
  /* huffman code lengths */
 
249
  unsigned char PRETREE_len  [LZX_PRETREE_MAXSYMBOLS  + LZX_LENTABLE_SAFETY];
 
250
  unsigned char MAINTREE_len [LZX_MAINTREE_MAXSYMBOLS + LZX_LENTABLE_SAFETY];
 
251
  unsigned char LENGTH_len   [LZX_LENGTH_MAXSYMBOLS   + LZX_LENTABLE_SAFETY];
 
252
  unsigned char ALIGNED_len  [LZX_ALIGNED_MAXSYMBOLS  + LZX_LENTABLE_SAFETY];
 
253
 
 
254
  /* huffman decoding tables */
 
255
  unsigned short PRETREE_table [(1 << LZX_PRETREE_TABLEBITS) +
 
256
                                (LZX_PRETREE_MAXSYMBOLS * 2)];
 
257
  unsigned short MAINTREE_table[(1 << LZX_MAINTREE_TABLEBITS) +
 
258
                                (LZX_MAINTREE_MAXSYMBOLS * 2)];
 
259
  unsigned short LENGTH_table  [(1 << LZX_LENGTH_TABLEBITS) +
 
260
                                (LZX_LENGTH_MAXSYMBOLS * 2)];
 
261
  unsigned short ALIGNED_table [(1 << LZX_ALIGNED_TABLEBITS) +
 
262
                                (LZX_ALIGNED_MAXSYMBOLS * 2)];
 
263
  unsigned char  input_end;       /* have we reached the end of input?       */
 
264
  unsigned char wflag;            /* write flag */
 
265
 
 
266
  /* this is used purely for doing the intel E8 transform */
 
267
  unsigned char  e8_buf[LZX_FRAME_SIZE];
 
268
 
 
269
  unsigned int  position_base[51];
 
270
 
 
271
  /* cabinet related stuff */
 
272
  struct cab_file *file;
 
273
  int (*read_cb)(struct cab_file *, unsigned char *, int);
 
274
 
 
275
  unsigned char extra_bits[51];
 
276
 
 
277
};
 
278
 
 
279
struct lzx_stream *lzx_init(int ofd,
 
280
                              int window_bits,
 
281
                              int reset_interval,
 
282
                              int input_buffer_size,
 
283
                              off_t output_length,
 
284
                              struct cab_file *file,
 
285
                              int (*read_cb)(struct cab_file *, unsigned char *, int));
 
286
 
 
287
extern void lzx_set_output_length(struct lzx_stream *lzx,
 
288
                                   off_t output_length);
 
289
 
 
290
extern int lzx_decompress(struct lzx_stream *lzx, uint32_t out_bytes);
 
291
 
 
292
void lzx_free(struct lzx_stream *lzx);
 
293
 
 
294
#endif