From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Amritpal Singh Newsgroups: gmane.emacs.bugs Subject: bug#63832: fix failed inflation of .el.gz archives due to passing empty buffer to inflate() Date: Fri, 2 Jun 2023 12:21:07 +0530 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="000000000000c48edd05fd1ffa82" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37940"; mail-complaints-to="usenet@ciao.gmane.io" To: 63832@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jun 02 09:53:20 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q4zb6-0009f8-55 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 02 Jun 2023 09:53:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4zav-0003co-5y; Fri, 02 Jun 2023 03:53:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4zap-0003WA-IX for bug-gnu-emacs@gnu.org; Fri, 02 Jun 2023 03:53:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4zap-0005Lc-9D for bug-gnu-emacs@gnu.org; Fri, 02 Jun 2023 03:53:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q4zao-0000zz-PG for bug-gnu-emacs@gnu.org; Fri, 02 Jun 2023 03:53:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Amritpal Singh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 02 Jun 2023 07:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 63832 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16856923423762 (code B ref -1); Fri, 02 Jun 2023 07:53:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 2 Jun 2023 07:52:22 +0000 Original-Received: from localhost ([127.0.0.1]:39030 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q4za7-0000yT-R1 for submit@debbugs.gnu.org; Fri, 02 Jun 2023 03:52:22 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:41468) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q4yd9-0007j9-Qp for submit@debbugs.gnu.org; Fri, 02 Jun 2023 02:51:26 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q4yd6-0004Wb-QA for bug-gnu-emacs@gnu.org; Fri, 02 Jun 2023 02:51:21 -0400 Original-Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q4yd4-0007c4-VH for bug-gnu-emacs@gnu.org; Fri, 02 Jun 2023 02:51:20 -0400 Original-Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-4f60a27c4a2so1779408e87.2 for ; Thu, 01 Jun 2023 23:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685688677; x=1688280677; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=HOM1mZo2U4ZCcBwBq/Zlug7Ps1g+OYwhaw8lkE+YmWs=; b=G0EzcfEAwV13SCV2tqfBYeCYYIvFb0yrVsrOdcH0Q2Avz73E1pIy3r6BwtScrM0t7G aDO6ihZdUtSe2O4IT2YQ/foufUT/Rt09D4rX/HaFQYwpaKW8tdcoovlorfE8L2y6V8qL bikc+xG80O2LV3uSsHxQdt4Sc48VV7hKecVwij33g0qpVeUUHB9ZtSZjlZ2EnmoW3JtM kcTigCqzbh8yiCVET0NWZ8wkxJxg+u1RBHlRGN27kINKAB+N/OWeFoM8jZwBUrT1lEwV A53DunKhBowK/ItUC9YT0XQg6Wb8j31UIKRYdY2YcdOCMUKSjEkg0+Zo+lEQXGG4FfSo cAvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685688677; x=1688280677; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=HOM1mZo2U4ZCcBwBq/Zlug7Ps1g+OYwhaw8lkE+YmWs=; b=dNC8CgzlanPJhh5tVU8Ca3OOomr1+CzdzuFiP7opHAL7gxih79Hxr0WIaLh3vFP7fq H7g14ci41T/l1hvfrninDPSM4X9+5xsf3bpj4dPVczT2Hiby33g3cW1u+5xsYXBSJC5U RHD4koHS5GcMv+lnH+2GEHa47mMrZqe595CcidD/Lc3p6uAyBrZT7N+nYBR3k84E8y0U 9vxWJQARWr/bKSo24f7QYFHDDPM7BAX0snc8p/yuxOD16iCMTUACrgayEkrWmttLR3+o O2St/vZSu2ukikgttstaKk6Z3kX9p99Nv5smb4FlcnkMf184AEGpQxfEzCgy1pB6gObv 8jqg== X-Gm-Message-State: AC+VfDxGURdKW6xuws0DMzIOasyZoscgqxnyabbHZYMI4jnuolTRVC/P bHbAjuEFjGHaK24UxgG3oyStq3yEzK3Gm3rtuNLKA5tqKuXucg== X-Google-Smtp-Source: ACHHUZ6yNbwlhO9LtZKFaPpgGAW+FOzPr2O5Tv+jgqtRUvlfUtxQUTBkXqBvMqh8NRKz2be/phJ7sViYYPcuA7vqscI= X-Received: by 2002:a05:6512:6c:b0:4e8:5576:98f4 with SMTP id i12-20020a056512006c00b004e8557698f4mr1287085lfo.45.1685688676546; Thu, 01 Jun 2023 23:51:16 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::12d; envelope-from=icy.amrit@gmail.com; helo=mail-lf1-x12d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 02 Jun 2023 03:52:15 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:262744 Archived-At: --000000000000c48edd05fd1ffa82 Content-Type: text/plain; charset="UTF-8" Compile emacs with the 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 patch with a simple fix is attached below ============================ >From ffa8e140ed8b093c60f1238bf76935e815e82a21 Mon Sep 17 00:00:00 2001 From: icebarf 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 ========== In GNU Emacs 29.0.91 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.37, cairo version 1.16.0) of 2023-06-02 built on box System Description: KISS Linux Configured using: 'configure --prefix=/usr --enable-link-time-optimization --with-cairo --with-gnutls --with-imagemagick --with-modules --with-native-compilation --with-pgtk --with-jpeg --with-tiff --with-png --with-rsvg --with-webp --without-dbus --without-lcms2 --without-libsystemd --without-gif --without-gconf --without-gsettings --without-m17n-flt --without-selinux --without-x --without-xft --without-xaw3d --without-xim --without-xdbe 'CFLAGS=-O2 -pipe -march=native -mtune=native'' --000000000000c48edd05fd1ffa82 Content-Type: text/x-diff; charset="US-ASCII"; name="0001-check-stream.avail_in-as-well-when-looping-to-inflat.patch" Content-Disposition: attachment; filename="0001-check-stream.avail_in-as-well-when-looping-to-inflat.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lie7i8ws0 RnJvbSBmZmE4ZTE0MGVkOGIwOTNjNjBmMTIzOGJmNzY5MzVlODE1ZTgyYTIxIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBpY2ViYXJmIDxzeXNncmFtbWVyQHByb3Rvbm1haWwuY29tPgpE YXRlOiBGcmksIDIgSnVuIDIwMjMgMTA6NTE6MjEgKzA1MzAKU3ViamVjdDogW1BBVENIXSBjaGVj ayBzdHJlYW0uYXZhaWxfaW4gYXMgd2VsbCB3aGVuIGxvb3BpbmcgdG8gaW5mbGF0ZSBnegogYXJj aGl2ZQoKLS0tCiBzcmMvZGVjb21wcmVzcy5jIHwgMiArLQogMSBmaWxlIGNoYW5nZWQsIDEgaW5z ZXJ0aW9uKCspLCAxIGRlbGV0aW9uKC0pCgpkaWZmIC0tZ2l0IGEvc3JjL2RlY29tcHJlc3MuYyBi L3NyYy9kZWNvbXByZXNzLmMKaW5kZXggNmVmMTdkYi4uMTYyZjYxNiAxMDA2NDQKLS0tIGEvc3Jj L2RlY29tcHJlc3MuYworKysgYi9zcmMvZGVjb21wcmVzcy5jCkBAIC0xNTEsNyArMTUxLDcgQEAg bWQ1X2d6X3N0cmVhbSAoRklMRSAqc291cmNlLCB2b2lkICpyZXNibG9jaykKIAlyZXR1cm4gLTE7 CiAKICAgICAgIGFjY3VtdWxhdGVfYW5kX3Byb2Nlc3NfbWQ1IChvdXQsIE1ENV9CTE9DS1NJWkUg LSBzdHJlYW0uYXZhaWxfb3V0LCAmY3R4KTsKLSAgICB9IHdoaWxlICghc3RyZWFtLmF2YWlsX291 dCk7CisgICAgfSB3aGlsZSAoc3RyZWFtLmF2YWlsX2luICYmICFzdHJlYW0uYXZhaWxfb3V0KTsK IAogICB9IHdoaWxlIChyZXMgIT0gWl9TVFJFQU1fRU5EKTsKIAotLSAKMi40MC4xCgo= --000000000000c48edd05fd1ffa82--