Bug 478939 - SHA digest unable to read file with name ending in spaces
Summary: SHA digest unable to read file with name ending in spaces
Keywords:
Status: CLOSED NEXTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: perl
Version: 10
Hardware: All
OS: Linux
low
medium
Target Milestone: ---
Assignee: Stepan Kasal
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard: easy to fix; please just fix it.
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2009-01-06 04:35 UTC by Tim Taiwanese Liim
Modified: 2009-04-22 01:08 UTC (History)
6 users (show)

Fixed In Version: 5.10.0-68.fc10
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2009-04-22 01:08:40 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Tim Taiwanese Liim 2009-01-06 04:35:20 UTC
Description of problem:
    Digest::SHA refused to read files with name ending in spaces.  Feels
    like the module truncated trail spaces in filenames.


Version-Release number of selected component (if applicable):
    perl-Digest-SHA-5.45-52.fc10.x86_64


How reproducible:
    always.

Steps to Reproduce:
    1. mkdir t; cd t
    2. create t.pl as in "Additional info:" section.
       chmod +x t.pl
    3. create data files as follows:
           echo asdf     > "t "
           echo -e "0\c" > t
           cp t "t2 "
    4. ./t.pl *

Actual results:
    ==t==
    b6589fc6ab0dc82cf12099d1c2d40ab994e8410c t
    ==t ==
    b6589fc6ab0dc82cf12099d1c2d40ab994e8410c t 
    ==t2 ==
    Open failed: Bad file descriptor at ./t.pl line 17


Expected results:
    1. print the sha1sum of "t2 ", instead of bad file descriptor.
    2. sha1sum of "t " should be 7d97e98f8af710c7e7fe703abc8f639e0ee507c4.
       It looks like the calculation of "t " is taken from content
       of "t", ie. trailing space in filename truncated.

Additional info:
    1. the content of t.pl:
        #!/usr/bin/perl

        use           Digest::SHA;

        for (@ARGV) {
            print ("==$_==\n");
            printf("%s $_\n", &sha1sum($_));
        }

        sub sha1sum() {
            my $file = shift;
            my $algorithm = 1;
            my $sha1   = Digest::SHA->new($algorithm);
            if (! -r $file) {
                return "unreadable";
            }
            my $digest = $sha1->addfile($file);
            if (! defined($digest)){
                return "digest undefined, file $file";
            }
            my $hex = $digest->hexdigest;
            undef $digest;
            return $hex;
        }

Comment 1 Tim Taiwanese Liim 2009-01-06 17:09:52 UTC
Found the cause in pureperl module; not sure if the same
applies to the .so lib as well.  In file
    /usr/lib/perl5/5.10.0/i386-linux-thread-multi/Digest/SHA.pm
method 
    Addfile
we have
	open(FH, "<$file") or _bail("Open failed");
which should be
	open(FH, "<", $file) or _bail("Open failed");
ie. use 3 args for open instead of 2 args.  Apparently perl drops
trailing spaces when open(FH, "<$file").

BTW, I didn't create filenames with trailing spaces; some crazy
web browner did.

Comment 2 Tim Taiwanese Liim 2009-01-28 22:32:27 UTC
Wes,
Does the proposal in Comment #1 make sense to you?

Comment 3 Wes Hardaker 2009-02-05 00:48:26 UTC
Sorry for the delay in a response to this.  It's been a long few months of 2 trips and a VERY long illness.

I think the fix you mention sounds right.  I've logged a bug with the upstream about this and hopefully they'll fix it there.

In the mean time, I'm actually no longer the owner of the Digest-SHA package because it comes out of the base perl package now in F10 (which even I keep forgetting).  So I'm changing the component to that (where your patch can be applied).

Comment 4 Tim Taiwanese Liim 2009-02-05 15:47:23 UTC
Wes,
Thanks!  Hope you recover all ok.

Comment 5 Wes Hardaker 2009-02-05 16:54:17 UTC
This is apparently fixed already in the most recent Digest::SHA package too, FYI (according to the author).  It's done a different way because of backwards compatibility needs with older perl (pre 5.6).

Comment 6 Stepan Kasal 2009-03-23 15:15:15 UTC
(In reply to comment #5)
> This is apparently fixed already in the most recent Digest::SHA package too,

Yes, Digest-SHA/Changes says this was fixed in version 5.46.

This problem shoud be rt.cpan.org #34690, that would be:
http://rt.cpan.org/Ticket/Display.html?id=34690
(I cannot check it atm, rt.cpan.org does not respond.)

> It's done a different way because of backwards
> compatibility needs with older perl (pre 5.6).  

Yes, the fix still uses 2-arg open().

I'm going to update Digest::SHA in rawhide and Fedora 10 to the latest release, 5.47.

Comment 7 Fedora Update System 2009-03-23 17:22:20 UTC
perl-5.10.0-63.fc10 has been submitted as an update for Fedora 10.
http://admin.fedoraproject.org/updates/perl-5.10.0-63.fc10

Comment 8 Fedora Update System 2009-03-25 16:02:12 UTC
perl-5.10.0-64.fc10 has been pushed to the Fedora 10 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update perl'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/F10/FEDORA-2009-2992

Comment 9 Fedora Update System 2009-03-27 14:55:06 UTC
perl-5.10.0-64.fc10 has been pushed to the Fedora 10 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update perl'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/F10/FEDORA-2009-2992

Comment 10 Tim Taiwanese Liim 2009-03-31 01:11:20 UTC
Said fix works well for me.  I think we can close this bug.

I tried to add feedback at
http://admin.fedoraproject.org/updates/F10/FEDORA-2009-2992  
but got "server internal error" several times.  I had hard time
to recognize the colorful security code; I think the colored code
is too tough for robots and humans alike.

Comment 11 Fedora Update System 2009-04-07 15:50:10 UTC
perl-5.10.0-66.fc10 has been pushed to the Fedora 10 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update perl'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/F10/FEDORA-2009-2992

Comment 12 Fedora Update System 2009-04-09 16:17:11 UTC
perl-5.10.0-67.fc10 has been pushed to the Fedora 10 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update perl'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/F10/FEDORA-2009-2992

Comment 13 Fedora Update System 2009-04-15 17:59:02 UTC
perl-5.10.0-68.fc10 has been pushed to the Fedora 10 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update perl'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/F10/FEDORA-2009-2992

Comment 14 Fedora Update System 2009-04-22 00:54:18 UTC
perl-5.10.0-68.fc9 has been pushed to the Fedora 9 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 15 Fedora Update System 2009-04-22 01:07:57 UTC
perl-5.10.0-68.fc10 has been pushed to the Fedora 10 stable repository.  If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.