From 1271b338f42e4562fbbe9bb8dd23e6cdd3984460 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Tue, 3 Nov 2026 18:07:08 +0100 Subject: [PATCH] fix: keep listxml machines larger than a read --- scripts/scraper/romset_dat_importer.py | 13 ++++++++++--- tests/test_romset_recipes.py | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/scripts/scraper/romset_dat_importer.py b/scripts/scraper/romset_dat_importer.py index 80e663cd6..55a081af8 100644 --- a/scripts/scraper/romset_dat_importer.py +++ b/scripts/scraper/romset_dat_importer.py @@ -200,20 +200,22 @@ def _scan_listxml( and those holding one of *targets*. The document is 311 MB for MAME 0.289, so it is never held whole: the - reader keeps a sliding window just large enough to close the element it - is in the middle of. + window keeps the element still open from its start tag, and grows until + that element closes, whatever its size. """ found: dict[str, tuple[str | None, list[dict]]] = {} buffer = b"" while chunk := stream.read(LISTXML_CHUNK): buffer += chunk position = 0 + keep_from = None while True: match = _MACHINE.search(buffer, position) if not match: break end = buffer.find(b"", match.end()) if end == -1: + keep_from = match.start() break name = match.group(1).decode() wanted = selector(name) @@ -223,7 +225,12 @@ def _scan_listxml( parent = _ROMOF.search(match.group(2).decode()) found[name] = (parent.group(1) if parent else None, roms) position = end + len(b"") - buffer = buffer[position:] if position else buffer[-(2 * LISTXML_CHUNK) :] + if keep_from is None: + # No element open: only a start tag cut by the read can follow. + start = buffer.rfind(b"