[Boost-bugs] [Boost C++ Libraries] #5325: boost::uuids::detail::sha1 computes incorrect result on vs2010sp1.iso

Subject: [Boost-bugs] [Boost C++ Libraries] #5325: boost::uuids::detail::sha1 computes incorrect result on vs2010sp1.iso
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-03-17 02:04:16


#5325: boost::uuids::detail::sha1 computes incorrect result on vs2010sp1.iso
---------------------------------+------------------------------------------
 Reporter: frankrq2009@… | Owner: atompkins
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: uuid
  Version: Boost 1.45.0 | Severity: Problem
 Keywords: sha1 |
---------------------------------+------------------------------------------
 I wrote a program to compute the CRC32 and sha1 checksum, I found it can
 generate correct sha1 result only if the size of the checked file is not
 too big(e.g.,the size of virtualbox or linux kernel source), but when I
 checked vs2010sp1.iso which is around 1.6GB, the crc32 is correct, the
 sha1 is not the same as the output of sha1sum. The version of boost that I
 tested are 1.45.0,1.46.0 and 1.46.1, both on windows 7 and linux 2.6.36.
 I attach my source code here.

 #include <stdio.h>
 #ifdef WIN32
 #include <io.h>
 #else
 #include <sys/types.h>
 #endif
 #include <fcntl.h>
 #include <string.h>
 #include <errno.h>
 #include <exception>
 #include <boost/crc.hpp>
 #include <boost/uuid/sha1.hpp>

 const int bufSize = 4096;
 int main(int argc, char**argv)
 {
     if(argc < 2)
     {
         printf("Useage:\t%s FileName1 FileName2 ...\n",argv[0]);
         return 1;
     }
         char buf[bufSize];
     try
     {
         for(int i = 1; i < argc; ++i)
         {
             boost::crc_32_type crc;
             boost::uuids::detail::sha1 sha;

             int fd=::open(argv[i], O_RDONLY);
             if(fd<0)
             {
                                 printf("Failed to open file %s,
 error:%s\n", argv[i], strerror(errno));
                                 continue;
                         }
                         while(1)
                         {
                                 int n=::read(fd, buf, bufSize);
                                 if(n<=0)
                                         break;
                                 crc.process_bytes(buf, n);
                                 sha.process_bytes(buf, n);
                         };
                         ::close(fd);
                         unsigned int dig[5];
             sha.get_digest(dig);
                         printf("%s :\nCRC32 = %08x\nSHA1 = ",argv[i],
 crc.checksum());
                         for(i=0; i<5; ++i)
                 printf("%04x",dig[i]);
             printf("\n");
         }
         return 0;
     }
     catch(std::exception &e)
     {
         printf("Found an exception with '%s'\n",e.what());
         return 2;
     }
     catch(...)
     {
         printf("Found an unknown exception.\n");
         return 3;
     }
 }

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5325>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:05 UTC