Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ PHP NEWS
. Fixed imageaffinematrixget() and imageaffinematrixconcat() reporting the
wrong argument in error messages. (Weilin Du)

- Hash:
. Fixed a buffer overflow in hash_pbkdf2() with a large output length.
(Lazizbek Ergashev)

- Intl:
. Fixed a double-free when IntlGregorianCalendar construction fails after
the ICU constructor adopts the TimeZone. (iliaal)
Expand Down
5 changes: 2 additions & 3 deletions ext/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <config.h>
#endif

#include <math.h>
#include "php_hash.h"
#include "ext/standard/info.h"
#include "ext/standard/file.h"
Expand Down Expand Up @@ -1043,10 +1042,10 @@ PHP_FUNCTION(hash_pbkdf2)
}
digest_length = length;
if (!raw_output) {
digest_length = (zend_long) ceil((float) length / 2.0);
digest_length = (length + 1) / 2;
}

loops = (zend_long) ceil((float) digest_length / (float) ops->digest_size);
loops = (digest_length + ops->digest_size - 1) / ops->digest_size;

result = safe_emalloc(loops, ops->digest_size, 0);

Expand Down
19 changes: 19 additions & 0 deletions ext/hash/tests/hash_pbkdf2_large_length.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Hash: hash_pbkdf2() function : large output length
--FILE--
<?php

$length = 33554433;
$hash = hash_pbkdf2('md5', 'password', 'salt', 1, $length);

/* The last hexit comes from the first byte of the final PBKDF2 block. */
$block = intdiv(intdiv($length + 1, 2) - 1, 16) + 1;
$expected = bin2hex(hash_hmac('md5', 'salt' . pack('N', $block), 'password', true));

var_dump(strlen($hash));
var_dump($hash[$length - 1] === $expected[0]);

?>
--EXPECT--
int(33554433)
bool(true)
Loading