Bug 478939 - SHA digest unable to read file with name ending in spaces
SHA digest unable to read file with name ending in spaces
Status: CLOSED NEXTRELEASE
Product: Fedora
Classification: Fedora
Component: perl (Show other bugs)
10
All Linux
low Severity medium
: ---
: ---
Assigned To: Stepan Kasal
Fedora Extras Quality Assurance
easy to fix; please just fix it.
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2009-01-05 23:35 EST by Tim Taiwanese Liim
Modified: 2009-04-21 21:08 EDT (History)
6 users (show)

See Also:
Fixed In Version: 5.10.0-68.fc10
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2009-04-21 21:08:40 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description Tim Taiwanese Liim 2009-01-05 23:35:20 EST
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 12:09:52 EST
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 17:32:27 EST
Wes,
Does the proposal in Comment #1 make sense to you?
Comment 3 Wes Hardaker 2009-02-04 19:48:26 EST
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 10:47:23 EST
Wes,
Thanks!  Hope you recover all ok.
Comment 5 Wes Hardaker 2009-02-05 11:54:17 EST
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 11:15:15 EDT
(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 13:22:20 EDT
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 12:02:12 EDT
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 10:55:06 EDT
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-30 21:11:20 EDT
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 11:50:10 EDT
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 12:17:11 EDT
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 13:59:02 EDT
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-21 20:54:18 EDT
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-21 21:07:57 EDT
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.