Skip to content

Commit

Permalink
Fix race condition in PyStringMap keys method [GH-156]
Browse files Browse the repository at this point in the history
If the map was modified during a call to keys(), the keyset would change
size and cause an ArrayIndexOutOfBoundsException. This creates a copy of
the keyset and uses that throughout the method.

--HG--
extra : amend_source : 025dd98595b444af0c4ffb67ae4bd4252fb752b4
  • Loading branch information
tpoliaw committed Feb 23, 2020
1 parent b7b9dc4 commit 17f5122
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ https://github.com/jythontools/jython

Jython 2.7.2b4
Bugs fixed
- [ GH-156 ] Race condition in PyStringMap keys method
- [ 2862 ] Jython fails on Linux for normal user when installed by root

Jython 2.7.2b3
Expand Down
5 changes: 3 additions & 2 deletions src/org/python/core/PyStringMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,10 @@ public PyList keys() {

@ExposedMethod(doc = BuiltinDocs.dict_keys_doc)
final PyList stringmap_keys() {
PyObject[] keyArray = new PyObject[table.size()];
Object[] keys = table.keySet().toArray();
PyObject[] keyArray = new PyObject[keys.length];
int i = 0;
for (Object key : table.keySet()) {
for (Object key : keys) {
keyArray[i++] = keyToPy(key);
}
return new PyList(keyArray);
Expand Down

0 comments on commit 17f5122

Please sign in to comment.