X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=blobdiff_plain;f=libbb%2Funarchive.c;h=62ca2674e4aec15024a0ee1fc91050c30580a12a;hp=c3630b070960c0516785c165c4634f588d716d9e;hb=bc4e5966d81e22dd7ea57ef24025ffdbf9a0bcfd;hpb=8fdd042394b7395c13bee66afb45dd3875c60c63 diff --git a/libbb/unarchive.c b/libbb/unarchive.c index c3630b0..62ca267 100644 --- a/libbb/unarchive.c +++ b/libbb/unarchive.c @@ -61,11 +61,15 @@ seek_by_read(FILE* fd, size_t len) } static void -seek_sub_file(FILE *src_stream, const int count) +seek_sub_file(FILE *fd, const int count) { - /* Try to fseek as faster */ archive_offset += count; - seek_by_read(src_stream, count); + + /* Do not use fseek() on a pipe. It may fail with ESPIPE, leaving the + * stream at an undefined location. + */ + seek_by_read(fd, count); + return; } @@ -185,7 +189,7 @@ extract_archive(FILE *src_stream, FILE *out_stream, goto cleanup; } archive_offset += file_entry->size; - copy_file_chunk(src_stream, dst_stream, file_entry->size); + *err = copy_file_chunk(src_stream, dst_stream, file_entry->size); fclose(dst_stream); } break; @@ -194,7 +198,7 @@ extract_archive(FILE *src_stream, FILE *out_stream, if (mkdir(full_name, file_entry->mode) < 0) { if ((function & extract_quiet) != extract_quiet) { *err = -1; - perror_msg("%s: %s", __FUNCTION__, full_name); + perror_msg("Cannot make dir %s", full_name); } } } @@ -313,6 +317,7 @@ unarchive(FILE *src_stream, FILE *out_stream, buffer = extract_archive(src_stream, out_stream, file_entry, extract_function, prefix, err); + *err = 0; /* XXX: ignore extraction errors */ if (*err) { free_headers(file_entry); break; @@ -640,7 +645,8 @@ deb_extract(const char *package_filename, FILE *out_stream, else if (extract_function & extract_data_tar_gz) { ared_file = "data.tar.gz"; } else { - fprintf(stderr, "no file specified to extract -- extract_function=%x\n", extract_function); + opkg_msg(ERROR, "Internal error: extract_function=%x\n", + extract_function); *err = -1; goto cleanup; } @@ -667,7 +673,6 @@ deb_extract(const char *package_filename, FILE *out_stream, /* open a stream of decompressed data */ uncompressed_stream = gz_open(deb_stream, &gunzip_pid); if (uncompressed_stream == NULL) { - printf("%s: %d\n", __FUNCTION__, __LINE__); *err = -1; goto cleanup; } @@ -685,7 +690,12 @@ deb_extract(const char *package_filename, FILE *out_stream, free_header_ar(ar_header); break; } - seek_sub_file(deb_stream, ar_header->size); + if (fseek(deb_stream, ar_header->size, SEEK_CUR) == -1) { + opkg_perror(ERROR, "Couldn't fseek into %s", package_filename); + *err = -1; + free_header_ar(ar_header); + goto cleanup; + } free_header_ar(ar_header); } goto cleanup; @@ -695,7 +705,11 @@ deb_extract(const char *package_filename, FILE *out_stream, FILE *unzipped_opkg_stream; file_header_t *tar_header; archive_offset = 0; - fseek(deb_stream, 0, SEEK_SET); + if (fseek(deb_stream, 0, SEEK_SET) == -1) { + opkg_perror(ERROR, "Couldn't fseek into %s", package_filename); + *err = -1; + goto cleanup; + } unzipped_opkg_stream = gz_open(deb_stream, &unzipped_opkg_pid); if (unzipped_opkg_stream == NULL) { *err = -1;