bzip2.c: SA-05:14.bzip2 has been resolved by the author

in a different way.  Make the file just the same as it
is in the vendor branch to make it easier for future
upgrade.
This commit is contained in:
Xin LI 2007-03-28 07:45:41 +00:00
parent c737bf586a
commit 555470d474
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=167977

View File

@ -3,119 +3,26 @@
/*--- A block-sorting, lossless compressor bzip2.c ---*/ /*--- A block-sorting, lossless compressor bzip2.c ---*/
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/*-- /* ------------------------------------------------------------------
This file is a part of bzip2 and/or libbzip2, a program and This file is part of bzip2/libbzip2, a program and library for
library for lossless, block-sorting data compression. lossless, block-sorting data compression.
Copyright (C) 1996-2005 Julian R Seward. All rights reserved. bzip2/libbzip2 version 1.0.4 of 20 December 2006
Copyright (C) 1996-2006 Julian Seward <jseward@bzip.org>
Redistribution and use in source and binary forms, with or without Please read the WARNING, DISCLAIMER and PATENTS sections in the
modification, are permitted provided that the following conditions README file.
are met:
1. Redistributions of source code must retain the above copyright This program is released under the terms of the license contained
notice, this list of conditions and the following disclaimer. in the file LICENSE.
------------------------------------------------------------------ */
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Julian Seward, Cambridge, UK.
jseward@bzip.org
bzip2/libbzip2 version 1.0 of 21 March 2000
This program is based on (at least) the work of:
Mike Burrows
David Wheeler
Peter Fenwick
Alistair Moffat
Radford Neal
Ian H. Witten
Robert Sedgewick
Jon L. Bentley
For more information on these sources, see the manual.
--*/
/*----------------------------------------------------*/ /* Place a 1 beside your platform, and 0 elsewhere.
/*--- IMPORTANT ---*/ Generic 32-bit Unix.
/*----------------------------------------------------*/ Also works on 64-bit Unix boxes.
This is the default.
/*-- */
WARNING:
This program and library (attempts to) compress data by
performing several non-trivial transformations on it.
Unless you are 100% familiar with *all* the algorithms
contained herein, and with the consequences of modifying them,
you should NOT meddle with the compression or decompression
machinery. Incorrect changes can and very likely *will*
lead to disasterous loss of data.
DISCLAIMER:
I TAKE NO RESPONSIBILITY FOR ANY LOSS OF DATA ARISING FROM THE
USE OF THIS PROGRAM, HOWSOEVER CAUSED.
Every compression of a file implies an assumption that the
compressed file can be decompressed to reproduce the original.
Great efforts in design, coding and testing have been made to
ensure that this program works correctly. However, the
complexity of the algorithms, and, in particular, the presence
of various special cases in the code which occur with very low
but non-zero probability make it impossible to rule out the
possibility of bugs remaining in the program. DO NOT COMPRESS
ANY DATA WITH THIS PROGRAM AND/OR LIBRARY UNLESS YOU ARE PREPARED
TO ACCEPT THE POSSIBILITY, HOWEVER SMALL, THAT THE DATA WILL
NOT BE RECOVERABLE.
That is not to say this program is inherently unreliable.
Indeed, I very much hope the opposite is true. bzip2/libbzip2
has been carefully constructed and extensively tested.
PATENTS:
To the best of my knowledge, bzip2/libbzip2 does not use any
patented algorithms. However, I do not have the resources
available to carry out a full patent search. Therefore I cannot
give any guarantee of the above statement.
--*/
/* $FreeBSD$ */
/*----------------------------------------------------*/
/*--- and now for something much more pleasant :-) ---*/
/*----------------------------------------------------*/
/*---------------------------------------------*/
/*--
Place a 1 beside your platform, and 0 elsewhere.
--*/
/*--
Generic 32-bit Unix.
Also works on 64-bit Unix boxes.
This is the default.
--*/
#define BZ_UNIX 1 #define BZ_UNIX 1
/*-- /*--
@ -303,17 +210,17 @@ Char progNameReally[FILE_NAME_LEN];
FILE *outputHandleJustInCase; FILE *outputHandleJustInCase;
Int32 workFactor; Int32 workFactor;
static void panic ( Char* ) NORETURN; static void panic ( const Char* ) NORETURN;
static void ioError ( void ) NORETURN; static void ioError ( void ) NORETURN;
static void outOfMemory ( void ) NORETURN; static void outOfMemory ( void ) NORETURN;
static void configError ( void ) NORETURN; static void configError ( void ) NORETURN;
static void crcError ( void ) NORETURN; static void crcError ( void ) NORETURN;
static void cleanUpAndFail ( Int32 ) NORETURN; static void cleanUpAndFail ( Int32 ) NORETURN;
static void compressedStreamEOF ( void ) NORETURN; static void compressedStreamEOF ( void ) NORETURN;
static void copyFileName ( Char*, Char* ); static void copyFileName ( Char*, Char* );
static void* myMalloc ( Int32 ); static void* myMalloc ( Int32 );
static int applySavedFileAttrToOutputFile ( int fd ); static void applySavedFileAttrToOutputFile ( IntNative fd );
@ -459,10 +366,9 @@ void compressStream ( FILE *stream, FILE *zStream )
ret = fflush ( zStream ); ret = fflush ( zStream );
if (ret == EOF) goto errhandler_io; if (ret == EOF) goto errhandler_io;
if (zStream != stdout) { if (zStream != stdout) {
int fd = fileno ( zStream ); Int32 fd = fileno ( zStream );
if (fd < 0) goto errhandler_io; if (fd < 0) goto errhandler_io;
ret = applySavedFileAttrToOutputFile ( fd ); applySavedFileAttrToOutputFile ( fd );
if (ret != 0) goto errhandler_io;
ret = fclose ( zStream ); ret = fclose ( zStream );
outputHandleJustInCase = NULL; outputHandleJustInCase = NULL;
if (ret == EOF) goto errhandler_io; if (ret == EOF) goto errhandler_io;
@ -575,11 +481,10 @@ Bool uncompressStream ( FILE *zStream, FILE *stream )
closeok: closeok:
if (ferror(zStream)) goto errhandler_io; if (ferror(zStream)) goto errhandler_io;
if ( stream != stdout) { if (stream != stdout) {
int fd = fileno ( stream ); Int32 fd = fileno ( stream );
if (fd < 0) goto errhandler_io; if (fd < 0) goto errhandler_io;
ret = applySavedFileAttrToOutputFile ( fd ); applySavedFileAttrToOutputFile ( fd );
if (ret != 0) goto errhandler_io;
} }
ret = fclose ( zStream ); ret = fclose ( zStream );
if (ret == EOF) goto errhandler_io; if (ret == EOF) goto errhandler_io;
@ -838,7 +743,7 @@ void cleanUpAndFail ( Int32 ec )
/*---------------------------------------------*/ /*---------------------------------------------*/
static static
void panic ( Char* s ) void panic ( const Char* s )
{ {
fprintf ( stderr, fprintf ( stderr,
"\n%s: PANIC -- internal consistency error:\n" "\n%s: PANIC -- internal consistency error:\n"
@ -1051,6 +956,7 @@ Bool fileExists ( Char* name )
For non-Unix platforms, if we are not worrying about For non-Unix platforms, if we are not worrying about
security issues, simple this simply behaves like fopen. security issues, simple this simply behaves like fopen.
*/ */
static
FILE* fopen_output_safely ( Char* name, const char* mode ) FILE* fopen_output_safely ( Char* name, const char* mode )
{ {
# if BZ_UNIX # if BZ_UNIX
@ -1156,20 +1062,18 @@ void applySavedTimeInfoToOutputFile ( Char *dstName )
} }
static static
int applySavedFileAttrToOutputFile ( int fd ) void applySavedFileAttrToOutputFile ( IntNative fd )
{ {
# if BZ_UNIX # if BZ_UNIX
IntNative retVal; IntNative retVal;
retVal = fchmod ( fd, fileMetaInfo.st_mode ); retVal = fchmod ( fd, fileMetaInfo.st_mode );
if (retVal != 0) ERROR_IF_NOT_ZERO ( retVal );
return retVal;
(void) fchown ( fd, fileMetaInfo.st_uid, fileMetaInfo.st_gid ); (void) fchown ( fd, fileMetaInfo.st_uid, fileMetaInfo.st_gid );
/* chown() will in many cases return with EPERM, which can /* chown() will in many cases return with EPERM, which can
be safely ignored. be safely ignored.
*/ */
return 0;
# endif # endif
} }
@ -1197,13 +1101,13 @@ Bool containsDubiousChars ( Char* name )
/*---------------------------------------------*/ /*---------------------------------------------*/
#define BZ_N_SUFFIX_PAIRS 4 #define BZ_N_SUFFIX_PAIRS 4
Char* zSuffix[BZ_N_SUFFIX_PAIRS] const Char* zSuffix[BZ_N_SUFFIX_PAIRS]
= { ".bz2", ".bz", ".tbz2", ".tbz" }; = { ".bz2", ".bz", ".tbz2", ".tbz" };
Char* unzSuffix[BZ_N_SUFFIX_PAIRS] const Char* unzSuffix[BZ_N_SUFFIX_PAIRS]
= { "", "", ".tar", ".tar" }; = { "", "", ".tar", ".tar" };
static static
Bool hasSuffix ( Char* s, Char* suffix ) Bool hasSuffix ( Char* s, const Char* suffix )
{ {
Int32 ns = strlen(s); Int32 ns = strlen(s);
Int32 nx = strlen(suffix); Int32 nx = strlen(suffix);
@ -1214,7 +1118,8 @@ Bool hasSuffix ( Char* s, Char* suffix )
static static
Bool mapSuffix ( Char* name, Bool mapSuffix ( Char* name,
Char* oldSuffix, Char* newSuffix ) const Char* oldSuffix,
const Char* newSuffix )
{ {
if (!hasSuffix(name,oldSuffix)) return False; if (!hasSuffix(name,oldSuffix)) return False;
name[strlen(name)-strlen(oldSuffix)] = 0; name[strlen(name)-strlen(oldSuffix)] = 0;
@ -1239,8 +1144,8 @@ void compress ( Char *name )
switch (srcMode) { switch (srcMode) {
case SM_I2O: case SM_I2O:
copyFileName ( inName, "(stdin)" ); copyFileName ( inName, (Char*)"(stdin)" );
copyFileName ( outName, "(stdout)" ); copyFileName ( outName, (Char*)"(stdout)" );
break; break;
case SM_F2F: case SM_F2F:
copyFileName ( inName, name ); copyFileName ( inName, name );
@ -1249,7 +1154,7 @@ void compress ( Char *name )
break; break;
case SM_F2O: case SM_F2O:
copyFileName ( inName, name ); copyFileName ( inName, name );
copyFileName ( outName, "(stdout)" ); copyFileName ( outName, (Char*)"(stdout)" );
break; break;
} }
@ -1423,8 +1328,8 @@ void uncompress ( Char *name )
cantGuess = False; cantGuess = False;
switch (srcMode) { switch (srcMode) {
case SM_I2O: case SM_I2O:
copyFileName ( inName, "(stdin)" ); copyFileName ( inName, (Char*)"(stdin)" );
copyFileName ( outName, "(stdout)" ); copyFileName ( outName, (Char*)"(stdout)" );
break; break;
case SM_F2F: case SM_F2F:
copyFileName ( inName, name ); copyFileName ( inName, name );
@ -1437,7 +1342,7 @@ void uncompress ( Char *name )
break; break;
case SM_F2O: case SM_F2O:
copyFileName ( inName, name ); copyFileName ( inName, name );
copyFileName ( outName, "(stdout)" ); copyFileName ( outName, (Char*)"(stdout)" );
break; break;
} }
@ -1615,9 +1520,9 @@ void testf ( Char *name )
if (name == NULL && srcMode != SM_I2O) if (name == NULL && srcMode != SM_I2O)
panic ( "testf: bad modes\n" ); panic ( "testf: bad modes\n" );
copyFileName ( outName, "(none)" ); copyFileName ( outName, (Char*)"(none)" );
switch (srcMode) { switch (srcMode) {
case SM_I2O: copyFileName ( inName, "(stdin)" ); break; case SM_I2O: copyFileName ( inName, (Char*)"(stdin)" ); break;
case SM_F2F: copyFileName ( inName, name ); break; case SM_F2F: copyFileName ( inName, name ); break;
case SM_F2O: copyFileName ( inName, name ); break; case SM_F2O: copyFileName ( inName, name ); break;
} }
@ -1700,11 +1605,11 @@ void license ( void )
"bzip2, a block-sorting file compressor. " "bzip2, a block-sorting file compressor. "
"Version %s.\n" "Version %s.\n"
" \n" " \n"
" Copyright (C) 1996-2005 by Julian Seward.\n" " Copyright (C) 1996-2006 by Julian Seward.\n"
" \n" " \n"
" This program is free software; you can redistribute it and/or modify\n" " This program is free software; you can redistribute it and/or modify\n"
" it under the terms set out in the LICENSE file, which is included\n" " it under the terms set out in the LICENSE file, which is included\n"
" in the bzip2-1.0 source distribution.\n" " in the bzip2-1.0.4 source distribution.\n"
" \n" " \n"
" This program is distributed in the hope that it will be useful,\n" " This program is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n" " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
@ -1907,8 +1812,8 @@ IntNative main ( IntNative argc, Char *argv[] )
# endif # endif
# endif # endif
copyFileName ( inName, "(none)" ); copyFileName ( inName, (Char*)"(none)" );
copyFileName ( outName, "(none)" ); copyFileName ( outName, (Char*)"(none)" );
copyFileName ( progNameReally, argv[0] ); copyFileName ( progNameReally, argv[0] );
progName = &progNameReally[0]; progName = &progNameReally[0];
@ -1920,8 +1825,8 @@ IntNative main ( IntNative argc, Char *argv[] )
expand filename wildcards in arg list. expand filename wildcards in arg list.
--*/ --*/
argList = NULL; argList = NULL;
addFlagsFromEnvVar ( &argList, "BZIP2" ); addFlagsFromEnvVar ( &argList, (Char*)"BZIP2" );
addFlagsFromEnvVar ( &argList, "BZIP" ); addFlagsFromEnvVar ( &argList, (Char*)"BZIP" );
for (i = 1; i <= argc-1; i++) for (i = 1; i <= argc-1; i++)
APPEND_FILESPEC(argList, argv[i]); APPEND_FILESPEC(argList, argv[i]);