pmqs / zipdetails

zipdetails - Display details about the internal structure of Zip files.
50 stars 2 forks source link

Undefined opt_EncodingFrom is dereferenced when perl-encoding is not installed #22

Open chenxiaolong opened 3 months ago

chenxiaolong commented 3 months ago

When the perl encoding library isn't installed, for some of my zip files, if I run zipdetails -vv <file>, it fails with:

❯ zipdetails -vv <file>

00000000 00000003 00000004 50 4B 03 04 LOCAL HEADER #1       04034B50 (67324752)
00000004 00000004 00000001 14          Extract Zip Spec      14 (20) '2.0'
00000005 00000005 00000001 00          Extract OS            00 (0) 'MS-DOS'
00000006 00000007 00000002 08 00       General Purpose Flag  0008 (8)
                                       [Bit  3]              1 'Streamed'
00000008 00000009 00000002 00 00       Compression Method    0000 (0) 'Stored'
0000000A 0000000D 00000004 00 00 21 00 Modification Time     00210000 (2162688) 'Mon Dec 31 19:00:00 1979'
0000000E 00000011 00000004 00 00 00 00 CRC                   00000000 (0)
00000012 00000015 00000004 00 00 00 00 Compressed Size       00000000 (0)
00000016 00000019 00000004 00 00 00 00 Uncompressed Size     00000000 (0)
0000001A 0000001B 00000002 1C 00       Filename Length       001C (28)
0000001C 0000001D 00000002 00 00       Extra Length          0000 (0)
Can't call method "name" on an undefined value at /home/chenxiaolong/git/github/zipdetails/bin/zipdetails line 7110.

I did some debugging and it seems like the eval in getNativeLocale is eating the error. If I comment out the eval, then I get:

Can't locate encoding.pm in @INC (you may need to install the encoding module) (@INC entries checked: /usr/local/lib64/perl5/5.38 /usr/local/share/perl5/5.38 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at /home/chenxiaolong/git/github/zipdetails/bin/zipdetails line 6981.

It wasn't clear to me before that I had to install this library.

I'm unsure if the encoding library is meant to be an optional or required dependency. If it's a required dependency, is there a way to avoid suppressing the error (or alternatively, could the dependency be documented)?

Thanks!


(I'm using commit 66f376c946e4cbefe7b587461434b91476f8f2f9.)

pmqs commented 3 months ago

Hey @chenxiaolong

the encoding.pm module is a standard with all versions of Perl that this script supports (5.10.0 or greater) so you shouldn't have to install anything extra.

What platform are you running? What version of Perl do you have?

Have you a non-standard install by any chance that didn't include encoding.pm?

chenxiaolong commented 3 months ago

Oh, interesting. I'm using perl 5.38.2 on Fedora 40.

It seems there may be 2 encoding.pm files:

❯ sudo dnf provides '*/encoding.pm'
...
perl-encoding-4:3.00-505.fc40.x86_64 : Write your Perl script in non-ASCII or non-UTF-8
Repo        : @System
Matched from:
Filename    : /usr/lib64/perl5/vendor_perl/encoding.pm
...
perl-libs-4:5.38.2-506.fc40.x86_64 : The libraries for the perl run-time
Repo        : @System
Matched from:
Filename    : /usr/lib64/perl5/PerlIO/encoding.pm
...

The perl-encoding package is built from this module:

❯ rpm -qi perl-encoding | grep ^URL
URL         : https://metacpan.org/release/Encode

I'm not sure if Fedora does something different, but it looks like the encoding::_get_locale_encoding() and Encode::find_encoding() functions used in zipdetails only exists in the encoding.pm file from the perl-encoding package.

pmqs commented 3 months ago

Does installing that package sort the issue?

chenxiaolong commented 3 months ago

Yep, it does.

pmqs commented 3 months ago

Yep, it does.

Good stuff. Ping me if you have any other issues.