34 #pragma warning(disable : 4996)
40 #define fileno _fileno
41 #define fdopen _fdopen
42 #define setmode _setmode
55 "\n\nbzip2/libbzip2: internal error number %d.\n"
56 "This is a bug in bzip2/libbzip2, %s.\n"
57 "Please report it to me at: jseward@bzip.org. If this happened\n"
58 "when you were using some program which uses libbzip2 as a\n"
59 "component, you should also report this bug to the author(s)\n"
60 "of that program. Please make an effort to report this bug;\n"
61 "timely and accurate bug reports eventually lead to higher\n"
62 "quality software. Thanks. Julian Seward, 10 December 2007.\n\n",
67 if (errcode == 1007) {
69 "\n*** A special note about internal error number 1007 ***\n"
71 "Experience suggests that a common cause of i.e. 1007\n"
72 "is unreliable memory or other hardware. The 1007 assertion\n"
73 "just happens to cross-check the results of huge numbers of\n"
74 "memory reads/writes, and so acts (unintendedly) as a stress\n"
75 "test of your memory system.\n"
77 "I suggest the following: try compressing the file again,\n"
78 "possibly monitoring progress in detail with the -vv flag.\n"
80 "* If the error cannot be reproduced, and/or happens at different\n"
81 " points in compression, you may have a flaky memory system.\n"
82 " Try a memory-test program. I have used Memtest86\n"
83 " (www.memtest86.com). At the time of writing it is free (GPLd).\n"
84 " Memtest86 tests memory much more thorougly than your BIOSs\n"
85 " power-on test, and may find failures that the BIOS doesn't.\n"
87 "* If the error can be repeatably reproduced, this is a bug in\n"
88 " bzip2, and I would very much like to hear about it. Please\n"
89 " let me know, and, ideally, save a copy of the file causing the\n"
90 " problem -- without which I will be unable to investigate it.\n"
104 if (
sizeof(
int) != 4)
return 0;
105 if (
sizeof(
short) != 2)
return 0;
106 if (
sizeof(
char) != 1)
return 0;
115 void* v =
malloc ( items * size );
122 if (addr != NULL)
free ( addr );
135 for (i = 0; i < 256; i++) s->
inUse[i] =
False;
171 blockSize100k < 1 || blockSize100k > 9 ||
172 workFactor < 0 || workFactor > 250)
175 if (workFactor == 0) workFactor = 30;
187 n = 100000 * blockSize100k;
192 if (s->
arr1 == NULL || s->
arr2 == NULL || s->
ftab == NULL) {
205 s->
nblockMAX = 100000 * blockSize100k - 19;
271 #define ADD_CHAR_TO_BLOCK(zs,zchh0) \
273 UInt32 zchh = (UInt32)(zchh0); \
275 if (zchh != zs->state_in_ch && \
276 zs->state_in_len == 1) { \
277 UChar ch = (UChar)(zs->state_in_ch); \
278 BZ_UPDATE_CRC( zs->blockCRC, ch ); \
279 zs->inUse[zs->state_in_ch] = True; \
280 zs->block[zs->nblock] = (UChar)ch; \
282 zs->state_in_ch = zchh; \
286 if (zchh != zs->state_in_ch || \
287 zs->state_in_len == 255) { \
288 if (zs->state_in_ch < 256) \
289 add_pair_to_block ( zs ); \
290 zs->state_in_ch = zchh; \
291 zs->state_in_len = 1; \
293 zs->state_in_len++; \
413 return progress_in || progress_out;
579 if (k1 != s->
k0) { s->
k0 = k1;
continue; };
585 if (k1 != s->
k0) { s->
k0 = k1;
continue; };
591 if (k1 != s->
k0) { s->
k0 = k1;
continue; };
615 UInt32 avail_out_INIT = cs_avail_out;
617 unsigned int total_out_lo32_old;
622 if (c_state_out_len > 0) {
624 if (cs_avail_out == 0)
goto return_notr;
625 if (c_state_out_len == 1)
break;
626 *( (
UChar*)(cs_next_out) ) = c_state_out_ch;
632 s_state_out_len_eq_one:
634 if (cs_avail_out == 0) {
635 c_state_out_len = 1;
goto return_notr;
637 *( (
UChar*)(cs_next_out) ) = c_state_out_ch;
644 if (c_nblock_used > s_save_nblockPP)
648 if (c_nblock_used == s_save_nblockPP) {
649 c_state_out_len = 0;
goto return_notr;
651 c_state_out_ch = c_k0;
654 c_k0 = k1;
goto s_state_out_len_eq_one;
656 if (c_nblock_used == s_save_nblockPP)
657 goto s_state_out_len_eq_one;
661 if (c_nblock_used == s_save_nblockPP)
continue;
662 if (k1 != c_k0) { c_k0 = k1;
continue; };
666 if (c_nblock_used == s_save_nblockPP)
continue;
667 if (k1 != c_k0) { c_k0 = k1;
continue; };
670 c_state_out_len = ((
Int32)k1) + 4;
704 mid = (nb + na) >> 1;
705 if (indx >= cftab[mid]) nb = mid;
else na = mid;
707 while (na - nb != 1);
749 if (k1 != s->
k0) { s->
k0 = k1;
continue; };
755 if (k1 != s->
k0) { s->
k0 = k1;
continue; };
761 if (k1 != s->
k0) { s->
k0 = k1;
continue; };
797 if (k1 != s->
k0) { s->
k0 = k1;
continue; };
802 if (k1 != s->
k0) { s->
k0 = k1;
continue; };
807 if (k1 != s->
k0) { s->
k0 = k1;
continue; };
856 VPrintf2 (
"\n combined CRCs: stored = 0x%08x, computed = 0x%08x",
897 #define BZ_SETERR(eee) \
899 if (bzerror != NULL) *bzerror = eee; \
900 if (bzf != NULL) bzf->lastErr = eee; \
919 Int32 c = fgetc ( f );
920 if (c == EOF)
return True;
940 (blockSize100k < 1 || blockSize100k > 9) ||
941 (workFactor < 0 || workFactor > 250) ||
942 (verbosity < 0 || verbosity > 4))
961 if (workFactor == 0) workFactor = 30;
963 verbosity, workFactor );
985 if (bzf == NULL || buf == NULL || len < 0)
1007 n2 = fwrite ( (
void*)(bzf->
buf),
sizeof(
UChar),
1009 if (n != n2 || ferror(bzf->
handle))
1024 unsigned int* nbytes_in,
1025 unsigned int* nbytes_out )
1028 nbytes_in, NULL, nbytes_out, NULL );
1036 unsigned int* nbytes_in_lo32,
1037 unsigned int* nbytes_in_hi32,
1038 unsigned int* nbytes_out_lo32,
1039 unsigned int* nbytes_out_hi32 )
1051 if (nbytes_in_lo32 != NULL) *nbytes_in_lo32 = 0;
1052 if (nbytes_in_hi32 != NULL) *nbytes_in_hi32 = 0;
1053 if (nbytes_out_lo32 != NULL) *nbytes_out_lo32 = 0;
1054 if (nbytes_out_hi32 != NULL) *nbytes_out_hi32 = 0;
1066 n2 = fwrite ( (
void*)(bzf->
buf),
sizeof(
UChar),
1068 if (n != n2 || ferror(bzf->
handle))
1076 if ( !abandon && !ferror ( bzf->
handle ) ) {
1082 if (nbytes_in_lo32 != NULL)
1084 if (nbytes_in_hi32 != NULL)
1086 if (nbytes_out_lo32 != NULL)
1088 if (nbytes_out_hi32 != NULL)
1112 (small != 0 && small != 1) ||
1113 (verbosity < 0 || verbosity > 4) ||
1114 (unused == NULL && nUnused != 0) ||
1115 (unused != NULL && (nUnused < 0 || nUnused >
BZ_MAX_UNUSED)))
1135 while (nUnused > 0) {
1137 unused = ((
void*)( 1 + ((
UChar*)(unused)) ));
1183 if (bzf == NULL || buf == NULL || len < 0)
1201 n = fread ( bzf->
buf,
sizeof(
UChar),
1243 if (unused == NULL || nUnused == NULL)
1260 unsigned int* destLen,
1262 unsigned int sourceLen,
1270 if (dest == NULL || destLen == NULL ||
1272 blockSize100k < 1 || blockSize100k > 9 ||
1273 verbosity < 0 || verbosity > 4 ||
1274 workFactor < 0 || workFactor > 250)
1277 if (workFactor == 0) workFactor = 30;
1282 verbosity, workFactor );
1283 if (ret !=
BZ_OK)
return ret;
1312 unsigned int* destLen,
1314 unsigned int sourceLen,
1321 if (dest == NULL || destLen == NULL ||
1323 (small != 0 && small != 1) ||
1324 verbosity < 0 || verbosity > 4)
1331 if (ret !=
BZ_OK)
return ret;
1339 if (ret ==
BZ_OK)
goto output_overflow_or_eof;
1347 output_overflow_or_eof:
1386 #if defined(_WIN32) || defined(OS2) || defined(MSDOS)
1389 # define SET_BINARY_MODE(file) setmode(fileno(file),O_BINARY)
1391 # define SET_BINARY_MODE(file)
1402 int blockSize100k = 9;
1404 char mode2[10] =
"";
1408 int workFactor = 30;
1412 if (mode == NULL)
return NULL;
1420 smallMode = 1;
break;
1422 if (isdigit((
int)(*mode))) {
1428 strcat(mode2, writing ?
"w" :
"r" );
1432 if (path==NULL ||
strcmp(path,
"")==0) {
1433 fp = (writing ? stdout : stdin);
1436 fp = fopen(path,mode2);
1439 #ifdef BZ_STRICT_ANSI
1442 fp = (FILE *)fdopen(fd,mode2);
1445 if (fp == NULL)
return NULL;
1449 if (blockSize100k < 1) blockSize100k = 1;
1450 if (blockSize100k > 9) blockSize100k = 9;
1452 verbosity,workFactor);
1458 if (fp != stdin && fp != stdout) fclose(fp);
1530 if (b==NULL) {
return;}
1531 fp = ((
bzFile *)b)->handle;
1532 if(((
bzFile*)b)->writing){
1540 if(fp!=stdin && fp!=stdout){
1572 int err = ((
bzFile *)b)->lastErr;
1576 return bzerrorstrings[err*-1];
int BZ_API() BZ2_bzDecompress(bz_stream *strm)
int BZ_API() BZ2_bzBuffToBuffDecompress(char *dest, unsigned int *destLen, char *source, unsigned int sourceLen, int small, int verbosity)
void BZ_API() BZ2_bzWrite(int *bzerror, BZFILE *b, void *buf, int len)
int BZ_API() BZ2_bzwrite(BZFILE *b, void *buf, int len)
static int bz_config_ok(void)
BZFILE *BZ_API() BZ2_bzdopen(int fd, const char *mode)
void BZ2_compressBlock(EState *, Bool)
#define SET_BINARY_MODE(file)
static Bool copy_output_until_stop(EState *s)
void BZ_API() BZ2_bzWriteClose(int *bzerror, BZFILE *b, int abandon, unsigned int *nbytes_in, unsigned int *nbytes_out)
#define BZ_FINALISE_CRC(crcVar)
unsigned int total_in_hi32
int BZ_API() BZ2_bzCompress(bz_stream *strm, int action)
void *(* bzalloc)(void *, int, int)
static const char * bzerrorstrings[]
#define BZ_UPDATE_CRC(crcVar, cha)
static Bool myfeof(FILE *f)
#define BZ_GET_FAST(cccc)
const char *BZ_API() BZ2_bzerror(BZFILE *b, int *errnum)
int BZ_API() BZ2_bzread(BZFILE *b, void *buf, int len)
unsigned int total_out_hi32
Int32 BZ2_indexIntoF(Int32 indx, Int32 *cftab)
ABC_NAMESPACE_IMPL_START void BZ2_bz__AssertH__fail(int errcode)
#define BZ_GET_FAST_C(cccc)
static void prepare_new_block(EState *s)
UInt32 calculatedBlockCRC
static Bool isempty_RL(EState *s)
#define VPrintf2(zf, za1, za2)
void BZ_API() BZ2_bzReadGetUnused(int *bzerror, BZFILE *b, void **unused, int *nUnused)
static Bool handle_compress(bz_stream *strm)
int BZ_API() BZ2_bzCompressEnd(bz_stream *strm)
BZFILE *BZ_API() BZ2_bzWriteOpen(int *bzerror, FILE *f, int blockSize100k, int verbosity, int workFactor)
int BZ_API() BZ2_bzflush(BZFILE *b)
#define AssertH(cond, errcode)
int BZ_API() BZ2_bzCompressInit(bz_stream *strm, int blockSize100k, int verbosity, int workFactor)
static Bool unRLE_obuf_to_output_SMALL(DState *s)
void BZ_API() BZ2_bzReadClose(int *bzerror, BZFILE *b)
unsigned int total_in_lo32
static void flush_RL(EState *s)
unsigned int total_out_lo32
Int32 BZ2_decompress(DState *)
#define ABC_NAMESPACE_IMPL_END
BZFILE *BZ_API() BZ2_bzReadOpen(int *bzerror, FILE *f, int verbosity, int small, void *unused, int nUnused)
int BZ_API() BZ2_bzRead(int *bzerror, BZFILE *b, void *buf, int len)
void BZ_API() BZ2_bzclose(BZFILE *b)
int BZ_API() BZ2_bzDecompressInit(bz_stream *strm, int verbosity, int small)
void BZ_API() BZ2_bzWriteClose64(int *bzerror, BZFILE *b, int abandon, unsigned int *nbytes_in_lo32, unsigned int *nbytes_in_hi32, unsigned int *nbytes_out_lo32, unsigned int *nbytes_out_hi32)
static void * default_bzalloc(void *opaque, Int32 items, Int32 size)
static Bool unRLE_obuf_to_output_FAST(DState *s)
#define ADD_CHAR_TO_BLOCK(zs, zchh0)
#define ABC_NAMESPACE_IMPL_START
void(* bzfree)(void *, void *)
static BZFILE * bzopen_or_bzdopen(const char *path, int fd, const char *mode, int open_mode)
int BZ_API() BZ2_bzDecompressEnd(bz_stream *strm)
#define BZ_UNEXPECTED_EOF
BZFILE *BZ_API() BZ2_bzopen(const char *path, const char *mode)
static void add_pair_to_block(EState *s)
#define BZ_INITIALISE_CRC(crcVar)
static void default_bzfree(void *opaque, void *addr)
int BZ_API() BZ2_bzBuffToBuffCompress(char *dest, unsigned int *destLen, char *source, unsigned int sourceLen, int blockSize100k, int verbosity, int workFactor)
const char *BZ_API() BZ2_bzlibVersion(void)
static void init_RL(EState *s)
UInt32 calculatedCombinedCRC
#define BZ_SEQUENCE_ERROR
#define BZ_GET_SMALL(cccc)
static Bool copy_input_until_stop(EState *s)