4
4
/*--- decompress.c ---*/
5
5
/*-------------------------------------------------------------*/
8
This file is a part of bzip2 and/or libbzip2, a program and
9
library for lossless, block-sorting data compression.
11
Copyright (C) 1996-2000 Julian R Seward. All rights reserved.
13
Redistribution and use in source and binary forms, with or without
14
modification, are permitted provided that the following conditions
17
1. Redistributions of source code must retain the above copyright
18
notice, this list of conditions and the following disclaimer.
20
2. The origin of this software must not be misrepresented; you must
21
not claim that you wrote the original software. If you use this
22
software in a product, an acknowledgment in the product
23
documentation would be appreciated but is not required.
25
3. Altered source versions must be plainly marked as such, and must
26
not be misrepresented as being the original software.
28
4. The name of the author may not be used to endorse or promote
29
products derived from this software without specific prior written
32
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
33
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
36
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
38
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44
Julian Seward, Cambridge, UK.
46
bzip2/libbzip2 version 1.0 of 21 March 2000
48
This program is based on (at least) the work of:
58
For more information on these sources, see the manual.
7
/* ------------------------------------------------------------------
8
This file is part of bzip2/libbzip2, a program and library for
9
lossless, block-sorting data compression.
11
bzip2/libbzip2 version 1.0.5 of 10 December 2007
12
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
14
Please read the WARNING, DISCLAIMER and PATENTS sections in the
17
This program is released under the terms of the license contained
19
------------------------------------------------------------------ */
62
22
#include "bzlib_private.h"
235
195
switch (s->state) {
237
197
GET_UCHAR(BZ_X_MAGIC_1, uc);
238
if (uc != 'B') RETURN(BZ_DATA_ERROR_MAGIC);
198
if (uc != BZ_HDR_B) RETURN(BZ_DATA_ERROR_MAGIC);
240
200
GET_UCHAR(BZ_X_MAGIC_2, uc);
241
if (uc != 'Z') RETURN(BZ_DATA_ERROR_MAGIC);
201
if (uc != BZ_HDR_Z) RETURN(BZ_DATA_ERROR_MAGIC);
243
203
GET_UCHAR(BZ_X_MAGIC_3, uc)
244
if (uc != 'h') RETURN(BZ_DATA_ERROR_MAGIC);
204
if (uc != BZ_HDR_h) RETURN(BZ_DATA_ERROR_MAGIC);
246
206
GET_BITS(BZ_X_MAGIC_4, s->blockSize100k, 8)
247
if (s->blockSize100k < '1' ||
248
s->blockSize100k > '9') RETURN(BZ_DATA_ERROR_MAGIC);
249
s->blockSize100k -= '0';
207
if (s->blockSize100k < (BZ_HDR_0 + 1) ||
208
s->blockSize100k > (BZ_HDR_0 + 9)) RETURN(BZ_DATA_ERROR_MAGIC);
209
s->blockSize100k -= BZ_HDR_0;
251
211
if (s->smallDecompress) {
252
212
s->ll16 = BZALLOC( s->blockSize100k * 100000 * sizeof(UInt16) );
524
484
if (s->origPtr < 0 || s->origPtr >= nblock)
525
485
RETURN(BZ_DATA_ERROR);
487
/*-- Set up cftab to facilitate generation of T^(-1) --*/
489
for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1];
490
for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1];
491
for (i = 0; i <= 256; i++) {
492
if (s->cftab[i] < 0 || s->cftab[i] > nblock) {
493
/* s->cftab[i] can legitimately be == nblock */
494
RETURN(BZ_DATA_ERROR);
527
498
s->state_out_len = 0;
528
499
s->state_out_ch = 0;
529
500
BZ_INITIALISE_CRC ( s->calculatedBlockCRC );
530
501
s->state = BZ_X_OUTPUT;
531
502
if (s->verbosity >= 2) VPrintf0 ( "rt+rld" );
533
/*-- Set up cftab to facilitate generation of T^(-1) --*/
535
for (i = 1; i <= 256; i++) s->cftab[i] = s->unzftab[i-1];
536
for (i = 1; i <= 256; i++) s->cftab[i] += s->cftab[i-1];
538
504
if (s->smallDecompress) {
540
506
/*-- Make a copy of cftab, used in generation of T --*/