小编Rom*_*man的帖子

是subprocess.Popen不是线程安全的吗?

以下简单脚本在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()
Run Code Online (Sandbox Code Playgroud)


上面引用的shell脚本(factorial.sh):

#!/bin/sh
echo "Calculating factorial (anything that's somewhat compute …
Run Code Online (Sandbox Code Playgroud)

python concurrency subprocess popen thread-safety

11
推荐指数
1
解决办法
4679
查看次数

在Java中的私有静态嵌套类中访问修饰符

我在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(){}
    }
}
Run Code Online (Sandbox Code Playgroud)

java methods static class access-modifiers

8
推荐指数
2
解决办法
6514
查看次数

用PHP破解Bcrypt?可以轻松包含任何恶意负载

盐:可以是任何东西.
工作因素:可以是任何东西.
以下所有内容都生成相同的哈希!

$pad = base64_decode('/gB=');
$data = array(
    'LegitimatePayload',
    'LaterSwitchedToMaliciousPayload',
    'Abracadabra',
    'hatIsGoingOn',
    'CanBeAlmostAnything',
);

foreach($data as $str){
    echo crypt($pad.$str, '$2a$04$AnySaltHere')."<br>\n";
}
Run Code Online (Sandbox Code Playgroud)


输出:

$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
Run Code Online (Sandbox Code Playgroud)

编辑:
这是一个字符串,它具有相同的前两个字节但具有不同的散列:
base64_decode('/ gBQyoK71jVY/J7QuBNJuFdxyf2eTBCs42chkx6ZvpJYszpzg ===')
如果php在第一个NUL字节处停止,那么你如何解释这个?

php security encryption bcrypt collision

-4
推荐指数
2
解决办法
521
查看次数