components/php/php56/patches/70312.patch
changeset 5116 867d838118ad
equal deleted inserted replaced
5115:9c865404b7f5 5116:867d838118ad
       
     1 # Source: upstream
       
     2 # http://git.php.net/?p=php-src.git;a=commit;h=1390a5812b151e0ea8f74e64bfeaa5df4dd5b801
       
     3 # https://bugs.php.net/bug.php?id=70312
       
     4 # Security
       
     5 
       
     6 From 1390a5812b151e0ea8f74e64bfeaa5df4dd5b801 Mon Sep 17 00:00:00 2001
       
     7 From: Stanislav Malyshev <[email protected]>
       
     8 Date: Tue, 1 Sep 2015 01:16:30 -0700
       
     9 Subject: [PATCH] Fix bug #70312 - HAVAL gives wrong hashes in specific cases
       
    10 
       
    11 ---
       
    12  ext/hash/hash_haval.c        | 10 +++++-----
       
    13  ext/hash/tests/bug70312.phpt | 18 ++++++++++++++++++
       
    14  2 files changed, 23 insertions(+), 5 deletions(-)
       
    15  create mode 100644 ext/hash/tests/bug70312.phpt
       
    16 
       
    17 diff --git a/ext/hash/hash_haval.c b/ext/hash/hash_haval.c
       
    18 index 32437ce..2102743 100644
       
    19 --- a/ext/hash/hash_haval.c
       
    20 +++ b/ext/hash/hash_haval.c
       
    21 @@ -336,7 +336,7 @@ PHP_HASH_API void PHP_HAVAL128Final(unsigned char *digest, PHP_HAVAL_CTX * conte
       
    22  
       
    23  	/* Pad out to 118 mod 128.
       
    24  	 */
       
    25 -	index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
       
    26 +	index = (unsigned int) ((context->count[0] >> 3) & 0x7f);
       
    27  	padLen = (index < 118) ? (118 - index) : (246 - index);
       
    28  	PHP_HAVALUpdate(context, PADDING, padLen);
       
    29  
       
    30 @@ -390,7 +390,7 @@ PHP_HASH_API void PHP_HAVAL160Final(unsigned char *digest, PHP_HAVAL_CTX * conte
       
    31  
       
    32  	/* Pad out to 118 mod 128.
       
    33  	 */
       
    34 -	index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
       
    35 +	index = (unsigned int) ((context->count[0] >> 3) & 0x7f);
       
    36  	padLen = (index < 118) ? (118 - index) : (246 - index);
       
    37  	PHP_HAVALUpdate(context, PADDING, padLen);
       
    38  
       
    39 @@ -444,7 +444,7 @@ PHP_HASH_API void PHP_HAVAL192Final(unsigned char *digest, PHP_HAVAL_CTX * conte
       
    40  
       
    41  	/* Pad out to 118 mod 128.
       
    42  	 */
       
    43 -	index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
       
    44 +	index = (unsigned int) ((context->count[0] >> 3) & 0x7f);
       
    45  	padLen = (index < 118) ? (118 - index) : (246 - index);
       
    46  	PHP_HAVALUpdate(context, PADDING, padLen);
       
    47  
       
    48 @@ -484,7 +484,7 @@ PHP_HASH_API void PHP_HAVAL224Final(unsigned char *digest, PHP_HAVAL_CTX * conte
       
    49  
       
    50  	/* Pad out to 118 mod 128.
       
    51  	 */
       
    52 -	index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
       
    53 +	index = (unsigned int) ((context->count[0] >> 3) & 0x7f);
       
    54  	padLen = (index < 118) ? (118 - index) : (246 - index);
       
    55  	PHP_HAVALUpdate(context, PADDING, padLen);
       
    56  
       
    57 @@ -525,7 +525,7 @@ PHP_HASH_API void PHP_HAVAL256Final(unsigned char *digest, PHP_HAVAL_CTX * conte
       
    58  
       
    59  	/* Pad out to 118 mod 128.
       
    60  	 */
       
    61 -	index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
       
    62 +	index = (unsigned int) ((context->count[0] >> 3) & 0x7f);
       
    63  	padLen = (index < 118) ? (118 - index) : (246 - index);
       
    64  	PHP_HAVALUpdate(context, PADDING, padLen);
       
    65  
       
    66 diff --git a/ext/hash/tests/bug70312.phpt b/ext/hash/tests/bug70312.phpt
       
    67 new file mode 100644
       
    68 index 0000000..5ded1ac
       
    69 --- /dev/null
       
    70 +++ b/ext/hash/tests/bug70312.phpt
       
    71 @@ -0,0 +1,18 @@
       
    72 +--TEST--
       
    73 +Bug #70312 HAVAL gives wrong hashes in specific cases
       
    74 +--SKIPIF--
       
    75 +<?php if(!extension_loaded("hash")) print "skip"; ?>
       
    76 +--FILE--
       
    77 +<?php
       
    78 +var_dump(hash('haval128,5', '1234567890123456789012345678901234567890123456789012345678901234'));
       
    79 +var_dump(hash('haval160,5', '1234567890123456789012345678901234567890123456789012345678901234'));
       
    80 +var_dump(hash('haval192,5', '1234567890123456789012345678901234567890123456789012345678901234'));
       
    81 +var_dump(hash('haval224,5', '1234567890123456789012345678901234567890123456789012345678901234'));
       
    82 +var_dump(hash('haval256,5', '1234567890123456789012345678901234567890123456789012345678901234'));
       
    83 +?>
       
    84 +--EXPECTF--
       
    85 +string(32) "f3f0d23819b87228b4b70ee350afaa9d"
       
    86 +string(40) "aded6485e137f11d7292212ba3fa961714df0564"
       
    87 +string(48) "e53da2b16269fe732e9a898a96707a9f28404d7333b02286"
       
    88 +string(56) "c574fb307f0817b514b9bb2e7c4bfaffb7ad667aca3c8b523fefcf10"
       
    89 +string(64) "fb73c19300b14d5cb393d929bf005e6c2d459a4c9c009e9813af1d2d3637ee8f"
       
    90 \ No newline at end of file
       
    91 -- 
       
    92 2.1.4
       
    93 
       
    94