unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Amritpal Singh <icy.amrit@gmail.com>
To: 63831@debbugs.gnu.org
Subject: bug#63831: [PATCH] Elaboration on the bugfix for failed inflation of gz archives
Date: Sat, 3 Jun 2023 08:38:18 +0530	[thread overview]
Message-ID: <CAAtEfCGZxcMPxtiZpyH6x8DXWaAhWe8JwoobPm=qWdJwpAUJEw@mail.gmail.com> (raw)
In-Reply-To: <CAAtEfCFQ=9BDwEwrnhHUw9ct5yZ2gSg8PZhq7qJJZQibEPgLxQ@mail.gmail.com>

> Now after logging some code in $EMACS_REPO/src/decompress.c, it was
> learned that in the pigz specific case, `inflate()` was returning
> Z_BUF_ERROR(-5) which is an indicator for zstream's either `avail_in`
> or `avail_out` fields are 0.
>
> Observing the code in `$EMACS_REPO/src/decompress.c`
> L154:
>     } while (!stream.avail_out);
> only checks stream.avail_out and not stream.avail_in which also might
> have been set to 0. A special case here can be constructed where
> `avail_in` is 0, and the code keeps looping even though our input
> buffer is empty and thus causing a Z_BUF_ERROR. Placing a simple check
> for it fixes the bug in pigz's gz archives case and does not cause any
> issue with gzip archives.

I'd like to elaborate a bit further on this part mentioned in the bug
report-cum-patch email. The code in question where the bug occurs is
as follows:

> do {
>    stream.avail_in = fread (in, 1, MD5_BLOCKSIZE, source);
>    if (ferror (source)) {
>      inflateEnd (&stream);
>      return -1;
>    }
>    if (stream.avail_in == 0)
>      break;
>    stream.next_in = in;
>
>    do {
>      stream.avail_out = MD5_BLOCKSIZE;
>      stream.next_out = out;
>      res = inflate (&stream, Z_NO_FLUSH);
>
>      if (res != Z_OK && res != Z_STREAM_END)
>    return -1;
>
>      accumulate_and_process_md5 (out, MD5_BLOCKSIZE - stream.avail_out, &ctx);
L154:
>    } while (!stream.avail_out);
L155:
>
>  } while (res != Z_STREAM_END);


From here, it is a bit more clear what the originally mentioned `L154`
was referring to. The archives compressed using pigz set as the systems'
gzip program either via symlink as `gzip` in $PATH or using $GZIP_PROG,
fail to hash in this specific instance which is quite strange,
nonetheless this patch (provided in the original bug report) fixes the
issue of calling inflate() repeatedly (in the inner do-while() loop)
when we do not have any more input to process.

This happens so, as mentioned before, because `infalte()` can set
`stream.avail_in` to 0 which is the available number of bytes to
process. And since we're only checking if stream.avail_out hasn't been
set to 0 in the inner loop, the hashing fails even though our archive is
correctly made and decompresses successfully externally.

ps. The patch is in the original bug report.





      parent reply	other threads:[~2023-06-03  3:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-02  5:39 bug#63831: fix bug with failed inflation of .el.gz files in src/decompress.c Amritpal Singh
2023-06-02  8:05 ` bug#63831: Accidentally submit two bug reports for the same topic Amritpal Singh
2023-06-02 12:13   ` Eli Zaretskii
2023-06-03 21:27     ` Richard Stallman
2023-06-04  3:46       ` Amritpal Singh
2023-06-04  5:38         ` Eli Zaretskii
2023-06-04  5:47           ` Amritpal Singh
2023-06-04  6:30           ` bug#63831: fix bug with failed inflation of .el.gz files in src/decompress.c Michael Albinus
2023-06-04  5:01       ` bug#63831: Accidentally submit two bug reports for the same topic Eli Zaretskii
2023-06-04  6:13         ` Michael Albinus
2023-06-05  7:35           ` Richard Stallman
2023-06-05  8:17             ` Michael Albinus
2023-06-03  3:08 ` Amritpal Singh [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAAtEfCGZxcMPxtiZpyH6x8DXWaAhWe8JwoobPm=qWdJwpAUJEw@mail.gmail.com' \
    --to=icy.amrit@gmail.com \
    --cc=63831@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).