ircmaxell/RandomLib

unitialized offset

karimzah opened this issue · 6 comments

I am currently running the following code below


$factory = new RandomLib\Factory;
$generator = $factory->getMediumStrengthGenerator();
$randomString = $generator->generateString(128);

I am getting an unitialized offset error on Line 268
https://github.com/ircmaxell/RandomLib/blob/master/lib/RandomLib/Generator.php#L268

It's because line Line 266 is returning 113 bytes sometimes 117 bytes or sometimes 123 bytes
and a few times it doesn't error at all and the code works fine.
https://github.com/ircmaxell/RandomLib/blob/master/lib/RandomLib/Generator.php#L266

Any ideas on how I can investigate this further or try something that would fix the issue?

current setup on production is:
PHP Version 5.3.10-1ubuntu3.24
Aug 1 2016 20:14:32
SSL Version: OpenSSL/1.0.1
Host: x86_64-pc-linux-gnu
Ubuntu 12.04

I don't get this error on my development box which is on virtual box same php version and
ubuntu version 12.04, I have checked all the mbstring settings which are on and UTF-8 and
other PHP settings are the same.

Appreciate any help or advice on this issue, Thanks.

Which mixer are you using?

It's using the Hash, I got this by doing a var_dump($this->mixer) on the generate() function in the library
just before line 163
https://github.com/ircmaxell/RandomLib/blob/master/lib/RandomLib/Generator.php#L163

object(RandomLib\Mixer\Hash)#38 (1) { ["hash":protected]=> string(6) "sha512" }

it's because you're using mb_strlen overloading. Turn that off, and it'll work fine.

I will work to fix this longer term.

Please try latest master (I just pushed). It should fix your issue.

1.2.0 released, fixing issue

Yes it fixed the issue, well done. thanks 👍 .