Subject: bug#78636: 30.1; package-install-file errors with some tar files

From: Philip Kaludercic <[email-masked]>
Date: Mon, 09 Jun 2025 11:46:39 +0000

Eli Zaretskii <[email-masked]> writes:

>> Date: Thu, 29 May 2025 15:56:31 +0000
>> From:  Andy Rosen via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <[email-masked]>
>> 
>> Running 'package-install-file' on a tar file might throw a 'Wrong type argument: arrayp, nil' error from
>> 'tar--check-descriptor’.  The problem comes from assumptions made by 'package--description-file' and
>> tar-mode about the filenames contained in the tar file.  I’ve written a detailed description of the error and
>> root cause here.

The issue make sense to me and we should fix it.

>> I propose adding a 'condition-case' to 'package-install-file' to return a friendly message.
>> 
>> diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
>> index 82fcf439a11..01f659e6982 100644
>> --- a/lisp/emacs-lisp/package.el
>> +++ b/lisp/emacs-lisp/package.el
>> @@ -2439,8 +2439,10 @@ directory."
>>        (insert-file-contents-literally file)
>>        (set-visited-file-name file)
>>        (set-buffer-modified-p nil)
>> -      (when (string-match "\\.tar\\'" file) (tar-mode)))
>> -    (package-install-from-buffer)))
>> +      (when (string-match "\\.tar\\'" file) (tar-mode)
                                                ^
Please break the line here.  I initially missed the major-mode switch,
which confused me.

>> +            (condition-case nil
>> +                (package-install-from-buffer)
>> +       (error (message "%s is not a valid package file" (file-name-nondirectory file))))))))

I am not sure if this is just the formatting of the patch while
responding, but the indentation here is also misleading.

Also, can't we use `tar-header-block-tokenize' or some other function to
directly check if the file is a valid archive, instead of relying on
downstream signals being raised?

>>  
>>  ;;;###autoload
>>  (defun package-install-selected-packages (&optional noconfirm)
>> 
>> In GNU Emacs 30.1 (build 1, aarch64-apple-darwin21.6.0, NS
>>  appkit-2113.65 Version 12.7.6 (Build 21H1320)) of 2025-02-24 built on
>>  armbob.lan
>> Windowing system distributor 'Apple', version 10.3.2575
>> System Description:  macOS 15.5
>
> Philip, any comments?