From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#63832: fix failed inflation of .el.gz archives due to passing empty buffer to inflate() Date: Thu, 08 Jun 2023 12:43:11 +0300 Message-ID: <83cz262ssw.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5147"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 63832-done@debbugs.gnu.org To: Amritpal Singh Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jun 08 11:44:44 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 1q7CC9-00012p-EJ for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 08 Jun 2023 11:44:41 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q7CBt-00039o-2C; Thu, 08 Jun 2023 05:44:25 -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 1q7CBW-0002qk-Hr for bug-gnu-emacs@gnu.org; Thu, 08 Jun 2023 05:44:02 -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 1q7CBV-0003Sp-Tb for bug-gnu-emacs@gnu.org; Thu, 08 Jun 2023 05:44:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q7CBV-0007qP-PQ for bug-gnu-emacs@gnu.org; Thu, 08 Jun 2023 05:44:01 -0400 Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Thu, 08 Jun 2023 09:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 63832 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Mail-Followup-To: 63832@debbugs.gnu.org, eliz@gnu.org, icy.amrit@gmail.com Original-Received: via spool by 63832-done@debbugs.gnu.org id=D63832.168621739530085 (code D ref 63832); Thu, 08 Jun 2023 09:44:01 +0000 Original-Received: (at 63832-done) by debbugs.gnu.org; 8 Jun 2023 09:43:15 +0000 Original-Received: from localhost ([127.0.0.1]:55701 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q7CAk-0007pB-SN for submit@debbugs.gnu.org; Thu, 08 Jun 2023 05:43:15 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:41212) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q7CAi-0007ow-Hq for 63832-done@debbugs.gnu.org; Thu, 08 Jun 2023 05:43:13 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q7CAd-0003NM-AV; Thu, 08 Jun 2023 05:43:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=HLYdgrZYQZvirXubNaLxv7yyj1UFPpdYGHQ4T7Iqcuk=; b=KDh7Vg8vCMD6 Vn/fJzT9OCeOLiuXObhUoQVQvnL+5Q97bRU6BjDVjUt83/FLdV2Go1snmHBL0PsJl7eWj/jNZFXYg nIrtLb3kR+zVtuG86YzKp53rWh+vs1n9vYB3+xknbG9Dr4D7UTmptlYkRaiRitCH9dnxwi0fWGkzQ AtletrzcdyHCSBHb0NbSe1UowqdPYlA+Ogl7KVNY/M54UQEFYyttVXM703oRJwQmy4kXppzCdZslu Q2Iz3v1nkgo6bbaVdJ+4435duziFALyF4kLsjqs+cBQ4lyhgigoAN8cilwU69yS5ti62vq34pi5tv gWfB/0ULCiVnMgmHUMOdUg==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q7CAc-0003Uq-QM; Thu, 08 Jun 2023 05:43:07 -0400 In-Reply-To: (message from Amritpal Singh on Fri, 2 Jun 2023 12:21:07 +0530) 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:263117 Archived-At: > From: Amritpal Singh > Date: Fri, 2 Jun 2023 12:21:07 +0530 > > 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 Thanks, installed on the master branch, and closing the bug.