-
-
Notifications
You must be signed in to change notification settings - Fork 890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mcrypt_generic(): is not a valid MCrypt resource #107
Comments
Please also provide your PHP version. |
PHP Version 5.3.2-1ubuntu4.18 MCrypt: |
I'll try to take a look in the next few days. Had a super busy weekend. Will be in San Francisco for a week starting this weekend so there may be more delays too but I'll do what I can :) |
Oh - something that'd help - do you think you could provide an example that isolates the problem? Thanks! |
This seems to be caused by the destructors of Net_SSH2 and Crypt_RC4. The PHP manual says
The last part seems to be important here and it looks like the Crypt_RC4 destructor is called before the Net_SSH2 destructor, Net_SSH2's destructor however uses Crypt_RC4 in |
Bantu, after your comment i was able to reproduce this error with the following script which will force the php engine to call Crypt_RC4::__destruct() before Crypt_SSH2::__destruct() on script_shutdown. (Note: For Linux, i had to use $i < 11 instead of $i < 6 to trigger the error... for what php-internal reasons ever... maybe on your machine you have playing around with $i) (Note: Ensure that the ssh server supports RC4... openssh will support it) ini_set('error_reporting',E_ALL);
require_once('Net/SSH2.php');
require_once('Crypt/RC4.php');
define('CRYPT_RC4_MODE', CRYPT_RC4_MODE_MCRYPT);
// for ($i = 0; $i < 11; $i++) // on Linux
for ($i = 0; $i < 6; $i++) // on Windows
{
$idx = $i % 2;
$ssh[$idx] = new Net_SSH2('192.168.184.129');
$ssh[$idx]->login('testuser', '****************');
}
echo "exit(0)\n";
exit(0); Output:
It seems, that there are 2 possible ways to avoid this error. Personally... i don't like both ways :-) but in case of... i tend more to removing Crypt_RC4::__destruct() ... Is there maybe one more way to fix it? |
@Petrich Do you know whether calling mcrypt_module_close() is actually necessary? Are there any resources wasted if it is not called? The Net_SSH2 descructor seems to be more important because it closes a network connection, so I agree with you. It might be possible to force an order using register_shutdown_function or so, but it probably isn't straight forward. |
Have to look at all other destructors as well, this might not be a problem with RC4 only. |
Also, let us remove the outdated |
Also, the PHP manual should probably clearify what happens when two object reference are cleared at the same time as seems to be the case here. |
Grep for destruct: ./Net/SSH2.php: function __destruct()
./Net/SSH1.php: function __destruct()
./Crypt/RC4.php: function __destruct() |
It seems not. At least not in the context of __destruct()'ing. It seems that php closing the opened mcrypt module automatically if not needed anymore. I wrote a small testscript which checks the memory usage. Memory stays stable, even after 1.000.000 rounds. require_once('Crypt/RC4.php');
define('CRYPT_RC4_MODE', CRYPT_RC4_MODE_MCRYPT);
class Crypt_RC4_skipDestructor extends Crypt_RC4
{
function __destruct()
{
return;
}
}
if (!function_exists('memory_get_usage')) {function memory_get_usage(){};} // if not available, look at Linux::top or Windows::Taskmanager
for ($i = 0; true; ++$i) {
$idx = $i % 1000;
$cipher[$idx] = new Crypt_RC4_skipDestructor();
$cipher[$idx]->decrypt($cipher[$idx]->encrypt('a'));
echo "[$i] [".str_pad($idx, 3)."] mem usage: " . memory_get_usage() . " bytes\n";
} So it seems safe removing Crypt_RC4::__destruct() |
Okay, in that case, let's just remove it. Want to do that? |
Yes. But want wait Terra's comment also... maybe we miss something. But this would fix the bug. |
Removing Crypt_RC4's destructor works. Ugh I don't like the "[the destructor can be called in] any order during the shutdown sequence" behavior of PHP. |
Bantu, Terra... i removed the __destruct()'or in RC4 @deviarte This bug is fixed now. Could you download the current master-branch and let run your application with it? There should be no mcrypt_generic() warnings anymore. Greetings :-) |
Fixed for me. Closing. |
git-svn-id: http://phpseclib.svn.sourceforge.net/svnroot/phpseclib/trunk@13 21d32557-59b3-4da0-833f-c5933fad653e
Hi,
We are using phpseclib for our internal app deployment and we just updated to the latest version of the library (master branch) and everything seemed to be fine.
But on some servers something goes wrong.
The deployment itself works fine (connecting/mkdir/upload/delete) but it generated this PHP error:
Severity: Warning
Message: mcrypt_generic(): 343 is not a valid MCrypt resource
Filename: Crypt/RC4.php
Line Number: 360
When we revert back to the old version of the library, every single server works fine:$Id: SSH2.php,v 1.53 2010-10-24 01:24:30 terrafrost Exp $
@Version
Note: Using a password as the authentication method.
Not sure if i am providing enough information to properly debug this.
Thanks!
The text was updated successfully, but these errors were encountered: