|
14 | 14 | # See the License for the specific language governing permissions and |
15 | 15 | # limitations under the License. |
16 | 16 |
|
| 17 | +import dataclasses |
17 | 18 | import datetime |
18 | 19 | import functools |
19 | 20 | import inspect |
| 21 | +import json |
20 | 22 | import logging |
21 | 23 | import os |
22 | | - |
23 | | -# Issue: [B403:blacklist] Consider possible security implications associated with pickle module. |
24 | | -# Severity: Low Confidence: High |
25 | | -# CWE: CWE-502 (https://cwe.mitre.org/data/definitions/502.html) |
26 | | -# More Info: https://bandit.readthedocs.io/en/1.8.3/blacklists/blacklist_imports.html#b403-import-pickle |
27 | | -import pickle # nosec |
28 | 24 | import sys |
29 | 25 | import time |
30 | 26 | from collections.abc import Iterable |
|
36 | 32 |
|
37 | 33 | from . import exception, utils |
38 | 34 | from .attribution import InterruptionRecord |
39 | | -from .state import Mode |
| 35 | +from .state import Mode, State |
40 | 36 |
|
41 | 37 |
|
42 | 38 | class BarrierError(exception.RestartError): |
@@ -109,30 +105,26 @@ def send_heartbeat(self, rank: int): |
109 | 105 | self.set(self.HEARTBEAT.format(rank=rank), str(time.time())) |
110 | 106 |
|
111 | 107 | def send_state(self, state, rank: int): |
112 | | - self.set(self.STATE.format(rank=rank), pickle.dumps(state)) |
| 108 | + state_dict = dataclasses.asdict(state) |
| 109 | + state_dict['mode'] = state.mode.name |
| 110 | + state_dict['fn_exception'] = None |
| 111 | + self.set(self.STATE.format(rank=rank), json.dumps(state_dict)) |
113 | 112 |
|
114 | 113 | def send_key(self, key, rank: int): |
115 | | - self.set(self.KEY.format(rank=rank), pickle.dumps(key)) |
| 114 | + self.set(self.KEY.format(rank=rank), json.dumps(key)) |
116 | 115 |
|
117 | 116 | def get_states(self, ranks): |
118 | | - states = [ |
119 | | - # Issue: [B301:blacklist] Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue. |
120 | | - # Severity: Medium Confidence: High |
121 | | - # CWE: CWE-502 (https://cwe.mitre.org/data/definitions/502.html) |
122 | | - # More Info: https://bandit.readthedocs.io/en/1.8.3/blacklists/blacklist_calls.html#b301-pickle |
123 | | - pickle.loads(state) # nosec |
124 | | - for state in self.multi_get([self.STATE.format(rank=rank) for rank in ranks]) |
125 | | - ] |
| 117 | + states = [] |
| 118 | + for data in self.multi_get([self.STATE.format(rank=rank) for rank in ranks]): |
| 119 | + state_dict = json.loads(data) |
| 120 | + state_dict['mode'] = Mode[state_dict['mode']] |
| 121 | + states.append(State(**state_dict)) |
126 | 122 | return states |
127 | 123 |
|
128 | 124 | def get_keys(self, ranks): |
129 | 125 | keys = [ |
130 | | - # Issue: [B301:blacklist] Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue. |
131 | | - # Severity: Medium Confidence: High |
132 | | - # CWE: CWE-502 (https://cwe.mitre.org/data/definitions/502.html) |
133 | | - # More Info: https://bandit.readthedocs.io/en/1.8.3/blacklists/blacklist_calls.html#b301-pickle |
134 | | - pickle.loads(key) # nosec |
135 | | - for key in self.multi_get([self.KEY.format(rank=rank) for rank in ranks]) |
| 126 | + json.loads(data) |
| 127 | + for data in self.multi_get([self.KEY.format(rank=rank) for rank in ranks]) |
136 | 128 | ] |
137 | 129 | return keys |
138 | 130 |
|
|
0 commit comments