Skip to content

Commit 88dbbc5

Browse files
committed
make hashlib threadsafe
1 parent 87f27ab commit 88dbbc5

File tree

2 files changed

+8
-352
lines changed

2 files changed

+8
-352
lines changed

Lib/test/test_hashlib.py

Lines changed: 0 additions & 349 deletions
This file was deleted.

src/org/python/modules/_hashlib.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ private static final MessageDigest getDigest(String name) {
162162
*/
163163
private MessageDigest cloneDigest() {
164164
try {
165-
return (MessageDigest)digest.clone();
165+
synchronized (this) {
166+
return (MessageDigest)digest.clone();
167+
}
166168
} catch (CloneNotSupportedException cnse) {
167169
throw Py.RuntimeError(String.format("_hashlib.HASH (%s) internal error", name));
168170
}
@@ -194,7 +196,10 @@ final void HASH_update(PyObject obj) {
194196
throw Py.TypeError("update() argument 1 must be string or read-only buffer, not "
195197
+ obj.getType().fastGetName());
196198
}
197-
digest.update(StringUtil.toBytes(string));
199+
byte[] input = StringUtil.toBytes(string);
200+
synchronized (this) {
201+
digest.update(input);
202+
}
198203
}
199204

200205
public PyObject digest() {
@@ -236,7 +241,7 @@ final PyObject HASH_copy() {
236241
}
237242

238243
@ExposedGet(name = "digestsize")
239-
public int getDigestSize() {
244+
public synchronized int getDigestSize() {
240245
return digest.getDigestLength();
241246
}
242247

0 commit comments

Comments
 (0)