aboutsummaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
Diffstat (limited to 'archival')
-rw-r--r--archival/libarchive/decompress_bunzip2.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/archival/libarchive/decompress_bunzip2.c b/archival/libarchive/decompress_bunzip2.c
index 7ef4e035f..6f2c49fbc 100644
--- a/archival/libarchive/decompress_bunzip2.c
+++ b/archival/libarchive/decompress_bunzip2.c
@@ -107,7 +107,7 @@ struct bunzip_data {
107 uint8_t selectors[32768]; /* nSelectors=15 bits */ 107 uint8_t selectors[32768]; /* nSelectors=15 bits */
108 struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */ 108 struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */
109}; 109};
110/* typedef struct bunzip_data bunzip_data; -- done in .h file */ 110typedef struct bunzip_data bunzip_data;
111 111
112 112
113/* Return the next nnn bits of input. All reads from the compressed input 113/* Return the next nnn bits of input. All reads from the compressed input
@@ -575,7 +575,7 @@ static int get_next_block(bunzip_data *bd)
575 in outbuf. IOW: on EOF returns len ("all bytes are not filled"), not 0. 575 in outbuf. IOW: on EOF returns len ("all bytes are not filled"), not 0.
576 (Why? This allows to get rid of one local variable) 576 (Why? This allows to get rid of one local variable)
577*/ 577*/
578int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len) 578static int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len)
579{ 579{
580 const uint32_t *dbuf; 580 const uint32_t *dbuf;
581 int pos, current, previous; 581 int pos, current, previous;
@@ -699,7 +699,7 @@ int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len)
699/* Because bunzip2 is used for help text unpacking, and because bb_show_usage() 699/* Because bunzip2 is used for help text unpacking, and because bb_show_usage()
700 should work for NOFORK applets too, we must be extremely careful to not leak 700 should work for NOFORK applets too, we must be extremely careful to not leak
701 any allocations! */ 701 any allocations! */
702int FAST_FUNC start_bunzip( 702static int FAST_FUNC start_bunzip(
703 void *jmpbuf, 703 void *jmpbuf,
704 bunzip_data **bdp, 704 bunzip_data **bdp,
705 int in_fd, 705 int in_fd,
@@ -759,7 +759,7 @@ int FAST_FUNC start_bunzip(
759 return RETVAL_OK; 759 return RETVAL_OK;
760} 760}
761 761
762void FAST_FUNC dealloc_bunzip(bunzip_data *bd) 762static void FAST_FUNC dealloc_bunzip(bunzip_data *bd)
763{ 763{
764 free(bd->dbuf); 764 free(bd->dbuf);
765 free(bd); 765 free(bd);
@@ -847,6 +847,36 @@ unpack_bz2_stream(transformer_state_t *xstate)
847 return i ? i : IF_DESKTOP(total_written) + 0; 847 return i ? i : IF_DESKTOP(total_written) + 0;
848} 848}
849 849
850char* FAST_FUNC
851unpack_bz2_data(const char *packed, int packed_len, int unpacked_len)
852{
853 char *outbuf = NULL;
854 bunzip_data *bd;
855 int i;
856 jmp_buf jmpbuf;
857
858 /* Setup for I/O error handling via longjmp */
859 i = setjmp(jmpbuf);
860 if (i == 0) {
861 i = start_bunzip(&jmpbuf,
862 &bd,
863 /* src_fd: */ -1,
864 /* inbuf: */ packed,
865 /* len: */ packed_len
866 );
867 }
868 /* read_bunzip can longjmp and end up here with i != 0
869 * on read data errors! Not trivial */
870 if (i == 0) {
871 /* Cannot use xmalloc: will leak bd in NOFORK case! */
872 outbuf = malloc_or_warn(unpacked_len);
873 if (outbuf)
874 read_bunzip(bd, outbuf, unpacked_len);
875 }
876 dealloc_bunzip(bd);
877 return outbuf;
878}
879
850#ifdef TESTING 880#ifdef TESTING
851 881
852static char *const bunzip_errors[] = { 882static char *const bunzip_errors[] = {