From b728ecdd4fe787012a0c1600104699337c042385 Mon Sep 17 00:00:00 2001 From: Sean Mullen Date: Wed, 11 Feb 2026 12:11:12 -0800 Subject: [PATCH 1/2] fixes case where truncate_corrupted_offsets() crashes due to _xml2dict returning None instead of {} if footer[info] is empty --- src/pyxdf/pyxdf.py | 2 +- test/test_truncate_corrupted_offsets.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/pyxdf/pyxdf.py b/src/pyxdf/pyxdf.py index fc82733..72b6c6c 100644 --- a/src/pyxdf/pyxdf.py +++ b/src/pyxdf/pyxdf.py @@ -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 diff --git a/test/test_truncate_corrupted_offsets.py b/test/test_truncate_corrupted_offsets.py index 574ddbd..cfb1e79 100644 --- a/test/test_truncate_corrupted_offsets.py +++ b/test/test_truncate_corrupted_offsets.py @@ -188,3 +188,26 @@ 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 + or . 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 From 01e746037338f3b8703fd80eee05ba35346a8f3d Mon Sep 17 00:00:00 2001 From: Sean Mullen Date: Wed, 25 Feb 2026 13:33:02 -0800 Subject: [PATCH 2/2] fix styling in unit test (ruff linter passes) --- test/test_truncate_corrupted_offsets.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test_truncate_corrupted_offsets.py b/test/test_truncate_corrupted_offsets.py index cfb1e79..0ac7a16 100644 --- a/test/test_truncate_corrupted_offsets.py +++ b/test/test_truncate_corrupted_offsets.py @@ -190,7 +190,6 @@ def test_truncation_of_samples_and_corrupted_clock_offset(): ) - def test_no_crash_when_footer_info_is_none(): """Streams with empty footer info (None) should be skipped gracefully. @@ -203,7 +202,7 @@ def test_no_crash_when_footer_info_is_none(): } streams = { 1: {"footer": {"info": {"sample_count": ["100"]}}}, - 2: {"footer": {"info": None}} + 2: {"footer": {"info": None}}, } # Should not raise AttributeError