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: fix bug with failed inflation of .el.gz files in src/decompress.c
Date: Fri, 2 Jun 2023 11:09:35 +0530	[thread overview]
Message-ID: <CAAtEfCFQ=9BDwEwrnhHUw9ct5yZ2gSg8PZhq7qJJZQibEPgLxQ@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1923 bytes --]

Bug Report:
Compile emacs with system's gzip program set to `pigz`.
Run emacs and then `M-x eww RET`

Expected behavior:
Enter URL prompt in mini-buffer

Actual behavior:
hashing failed '/usr/share/emacs/30.0.50/lisp/gnus/gnus.el.gz'

Report:
The bug has been reproduced on emacs version 29.0.91 and HEAD which
seems to be at 30.0.50.
Later, a copy of the aforementioned file was saved somewhere else and
the program was uninstalled. Then emacs was recompiled with system's
gzip program set to GNU gzip and the initial steps were repeated and
the expected behavior was the result.
This lead to believing either that there's a bug with how zlib's
`inflate()` handles archives or emacs code was having an issue with
archives files.

The hashes for gz archives generated with different programs were as follows
> md5sum gnus-gzip.el.gz
edb3d0ffba7f19ff1d4ec3f889609e8a  gnus-gzip.el.gz
> md5sum gnus.el.gz
985deaaec6a5845ac8d6bd9648957b50  gnus.el.gz

And when uncompressing these archives, the resulting file was the same
and the hash for the files was the same (omitted for brevity).

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.

A simple patch with a fix is attached below, I would also like to
thank a friend of mine cortexauth whom also helped during my debug
sessions.

[-- Attachment #2: 0001-check-stream.avail_in-as-well-when-looping-to-inflat.patch --]
[-- Type: text/x-diff, Size: 734 bytes --]

From ffa8e140ed8b093c60f1238bf76935e815e82a21 Mon Sep 17 00:00:00 2001
From: icebarf <sysgrammer@protonmail.com>
Date: Fri, 2 Jun 2023 10:51:21 +0530
Subject: [PATCH] check stream.avail_in as well when looping to inflate gz
 archive

---
 src/decompress.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/decompress.c b/src/decompress.c
index 6ef17db..162f616 100644
--- a/src/decompress.c
+++ b/src/decompress.c
@@ -151,7 +151,7 @@ md5_gz_stream (FILE *source, void *resblock)
 	return -1;
 
       accumulate_and_process_md5 (out, MD5_BLOCKSIZE - stream.avail_out, &ctx);
-    } while (!stream.avail_out);
+    } while (stream.avail_in && !stream.avail_out);
 
   } while (res != Z_STREAM_END);
 
-- 
2.40.1


             reply	other threads:[~2023-06-02  5:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-02  5:39 Amritpal Singh [this message]
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 ` bug#63831: [PATCH] Elaboration on the bugfix for failed inflation of gz archives Amritpal Singh

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='CAAtEfCFQ=9BDwEwrnhHUw9ct5yZ2gSg8PZhq7qJJZQibEPgLxQ@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).