Skip to content

Commit 8a174f5

Browse files
authored
Merge pull request datalad#4237 from mih/bf-annexjson
BF: Protect against multiple JSON records being read at once
2 parents e1c97fa + aef16cd commit 8a174f5

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

datalad/support/annexrepo.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,15 +3524,19 @@ def pipe_data_received(self, fd, data):
35243524
# this is where the JSON records come in
35253525
# json_loads() is already logging any error, which is OK, because
35263526
# under no circumstances we would expect broken JSON
3527-
try:
3528-
j = json_loads(data)
3529-
except Exception:
3530-
# TODO turn this into an error result, or put the exception
3531-
# onto the result future -- needs more thought
3532-
if data.strip():
3533-
# do not complain on empty lines
3534-
lgr.error('Received undecodable JSON output: %s', data)
3535-
return
3527+
for line in data.splitlines():
3528+
try:
3529+
j = json_loads(line)
3530+
except Exception:
3531+
# TODO turn this into an error result, or put the exception
3532+
# onto the result future -- needs more thought
3533+
if line.strip():
3534+
# do not complain on empty lines
3535+
lgr.error('Received undecodable JSON output: %s', data)
3536+
continue
3537+
self._proc_json_record(j)
3538+
3539+
def _proc_json_record(self, j):
35363540
# check for progress reports and act on them immediately
35373541
# but only if there is something to build a progress report from
35383542
if 'action' in j and 'byte-progress' in j:

0 commit comments

Comments
 (0)