Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pyxdf/pyxdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ def _truncate_corrupted_offsets(temp, streams):
for stream_id, stream in temp.items():
# First check if there are extra samples - this is the primary evidence
# of a potential pylsl#67, liblsl#246 bug.
footer = streams.get(stream_id, {}).get("footer", {}).get("info", {})
footer = streams.get(stream_id, {}).get("footer", {}).get("info") or {}
sample_count_str = footer.get("sample_count", [None])[0]
if sample_count_str is None:
continue
Expand Down
22 changes: 22 additions & 0 deletions test/test_truncate_corrupted_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,25 @@ def test_truncation_of_samples_and_corrupted_clock_offset():
expected_timestamps,
atol=1e-6,
)


def test_no_crash_when_footer_info_is_none():
"""Streams with empty footer info (None) should be skipped gracefully.

_xml2dict returns {"info": None} for empty XML elements like <info/>
or <info></info>. This must not crash _truncate_corrupted_offsets.
"""
temp = {
1: MockStreamData(time_stamps=np.linspace(0, 100, 100)),
2: MockStreamData(time_stamps=np.linspace(0, 50, 50)),
}
streams = {
1: {"footer": {"info": {"sample_count": ["100"]}}},
2: {"footer": {"info": None}},
}

# Should not raise AttributeError
result = _truncate_corrupted_offsets(temp, streams)

# Stream 2 should be unchanged
assert len(result[2].time_stamps) == 50