以下简单脚本在subprocess.Popen间歇性地挂起(大约30%的时间).
除非use_lock = True,然后它永远不会挂起,导致我相信子进程不是线程安全的!预期的行为是脚本在5-6秒内完成.
为了演示这个bug,只需运行几次"python bugProof.py"直到它挂起.Ctrl-C退出.你会看到'后Popen'只出现一次或两次,但不是第三次出现.
import subprocess, threading, fcntl, os, time
end_time = time.time()+5
lock = threading.Lock()
use_lock = False
path_to_factorial = os.path.join(os.path.dirname(os.path.realpath(__file__)),'factorial.sh')
def testFunction():
    print threading.current_thread().name, '| pre-Popen'
    if use_lock: lock.acquire()
    p = subprocess.Popen([path_to_factorial], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    if use_lock: lock.release()
    print threading.current_thread().name, '| post-Popen'
    fcntl.fcntl(p.stdout, fcntl.F_SETFL, os.O_NONBLOCK)
    fcntl.fcntl(p.stderr, fcntl.F_SETFL, os.O_NONBLOCK)
    while time.time()<end_time:
        try: p.stdout.read()
        except: pass
        try: p.stderr.read()
        except: pass
    print threading.current_thread().name, '| DONE'
for i in range(3):
    threading.Thread(target=testFunction).start()
上面引用的shell脚本(factorial.sh):
#!/bin/sh
echo "Calculating factorial (anything that's somewhat compute …我在Java中有一个"私有静态"嵌套类.访问修饰符对于此类中的字段和方法有何意义?我尝试过公开和私有对我的应用程序没有影响.
public class MyList<T>{
    private static class Node{ // List node
        private Object item;
        private Node next;
        private Node prev;
        private Node(Node next){
            this.next = next;
        }
        private static Node doStuff(){}
    }
}
盐:可以是任何东西.
工作因素:可以是任何东西.
以下所有内容都生成相同的哈希!
$pad = base64_decode('/gB=');
$data = array(
    'LegitimatePayload',
    'LaterSwitchedToMaliciousPayload',
    'Abracadabra',
    'hatIsGoingOn',
    'CanBeAlmostAnything',
);
foreach($data as $str){
    echo crypt($pad.$str, '$2a$04$AnySaltHere')."<br>\n";
}
输出:
$2a$04$AnySaltHere$$$$$$$$$$.m/QKi19jyBmSuP2VMcVuFRw.weCNRBa
$2a$04$AnySaltHere$$$$$$$$$$.m/QKi19jyBmSuP2VMcVuFRw.weCNRBa
$2a$04$AnySaltHere$$$$$$$$$$.m/QKi19jyBmSuP2VMcVuFRw.weCNRBa
$2a$04$AnySaltHere$$$$$$$$$$.m/QKi19jyBmSuP2VMcVuFRw.weCNRBa
$2a$04$AnySaltHere$$$$$$$$$$.m/QKi19jyBmSuP2VMcVuFRw.weCNRBa
$2a$04$AnySaltHere$$$$$$$$$$.m/QKi19jyBmSuP2VMcVuFRw.weCNRBa
编辑:
这是一个字符串,它具有相同的前两个字节但具有不同的散列:
base64_decode('/ gBQyoK71jVY/J7QuBNJuFdxyf2eTBCs42chkx6ZvpJYszpzg ===')
如果php在第一个NUL字节处停止,那么你如何解释这个?
bcrypt ×1
class ×1
collision ×1
concurrency ×1
encryption ×1
java ×1
methods ×1
php ×1
popen ×1
python ×1
security ×1
static ×1
subprocess ×1