Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80850 - in trunk: boost/uuid libs/uuid/test
From: atompkins_at_[hidden]
Date: 2012-10-04 14:36:09


Author: atompkins
Date: 2012-10-04 14:36:08 EDT (Thu, 04 Oct 2012)
New Revision: 80850
URL: http://svn.boost.org/trac/boost/changeset/80850

Log:
fixed bug in sha1.hpp for messages longer than 536,870,912 bytes
Text files modified:
   trunk/boost/uuid/sha1.hpp | 15 +++++++++++----
   trunk/libs/uuid/test/test_sha1.cpp | 3 +++
   2 files changed, 14 insertions(+), 4 deletions(-)

Modified: trunk/boost/uuid/sha1.hpp
==============================================================================
--- trunk/boost/uuid/sha1.hpp (original)
+++ trunk/boost/uuid/sha1.hpp 2012-10-04 14:36:08 EDT (Thu, 04 Oct 2012)
@@ -90,10 +90,17 @@
 {
     process_byte_impl(byte);
 
- bit_count_low += 8;
- if (bit_count_low == 0) {
- ++bit_count_high;
- if (bit_count_high == 0) {
+ // size_t max value = 0xFFFFFFFF
+ //if (bit_count_low + 8 >= 0x100000000) { // would overflow
+ //if (bit_count_low >= 0x100000000-8) {
+ if (bit_count_low < 0xFFFFFFF8) {
+ bit_count_low += 8;
+ } else {
+ bit_count_low = 0;
+
+ if (bit_count_high <= 0xFFFFFFFE) {
+ ++bit_count_high;
+ } else {
             BOOST_THROW_EXCEPTION(std::runtime_error("sha1 too many bytes"));
         }
     }

Modified: trunk/libs/uuid/test/test_sha1.cpp
==============================================================================
--- trunk/libs/uuid/test/test_sha1.cpp (original)
+++ trunk/libs/uuid/test/test_sha1.cpp 2012-10-04 14:36:08 EDT (Thu, 04 Oct 2012)
@@ -275,6 +275,9 @@
     };
     test_case cases[] =
     { { 1000000, { 0x34aa973c, 0xd4c4daa4, 0xf61eeb2b, 0xdbad2731, 0x6534016f } }
+ //, { 10000000, { 0xB43859B5, 0x3B0F90DA, 0x01951B6A, 0xB59CC964, 0xF3A8671A } }
+ //, { 100000000, { 0x812ED6A9, 0x31408FCA, 0x6B4881A1, 0xCD3308AE, 0x306CDE96 } }
+ //, { 536870912, { 0x0EA59BFE, 0x87879398, 0x16796610, 0xC73DEB1C, 0x625E03ED } }
     , { 1000000000, { 0xd0f3e4f2, 0xf31c665a, 0xbbd8f518, 0xe848d5cb, 0x80ca78f7 } }
     //, { 2000000000, { 0xda19be1b, 0x5ec3bc13, 0xda5533bd, 0x0c225a2f, 0x38da50ed } }
     //, { 2147483647, { 0x1e5b490b, 0x10255e37, 0xfd96d096, 0x4f2fbfb9, 0x1ed47536 } }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk