From 9a8179ef438ed57ad9e1fb34844eb4f9dae6b138 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Thu, 13 Apr 2023 08:15:22 -0400 Subject: ustar: Fix EOF logic --- diff --git a/src/gzip.c b/src/gzip.c index 472d656..f3fbdb9 100644 --- a/src/gzip.c +++ b/src/gzip.c @@ -65,13 +65,13 @@ static int _opkg_opk_gzip_next_record_from_file(struct opkg_opk_gzip_state *state) { for (;;) { - if (feof(state->input_file)) { - fclose(state->input_file); - state->input_file = NULL; - inflateEnd(&state->stream); - return OPKG_OPK_OK; - } if (state->stream.avail_in == 0) { + if (feof(state->input_file)) { + fclose(state->input_file); + state->input_file = NULL; + inflateEnd(&state->stream); + return OPKG_OPK_ERROR; + } state->stream.avail_in = fread(state->input_buffer, 1, OPKG_OPK_GZIP_BUFFER_SIZE, state->input_file); @@ -88,9 +88,13 @@ _opkg_opk_gzip_next_record_from_file(struct opkg_opk_gzip_state *state) } switch (inflate(&state->stream, Z_SYNC_FLUSH)) { case Z_OK: - case Z_STREAM_END: case Z_BUF_ERROR: break; + case Z_STREAM_END: + fclose(state->input_file); + state->input_file = NULL; + inflateEnd(&state->stream); + return OPKG_OPK_END; default: fclose(state->input_file); state->input_file = NULL; -- cgit v0.9.1