From e72b792f6f15e377e57d8e8652f7554dfc57d141 Mon Sep 17 00:00:00 2001 From: jan Date: Mon, 9 Mar 2026 01:45:06 -0700 Subject: [PATCH] [scan_hierarchy] make sure counts get reset at ref boundaries --- klamath/library.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/klamath/library.py b/klamath/library.py index f7b68bd..8b3ab20 100644 --- a/klamath/library.py +++ b/klamath/library.py @@ -220,10 +220,15 @@ def scan_hierarchy(stream: IO[bytes]) -> dict[bytes, dict[bytes, int]]: colrow = COLROW.read_data(stream, size) ref_count = colrow[0] * colrow[1] elif tag == ENDEL.tag: - if ref_count is None: - ref_count = 1 - assert ref_name is not None - cur_structure[ref_name] += ref_count + if ref_name is not None: + if ref_count is None: + ref_count = 1 + cur_structure[ref_name] += ref_count + ref_name = None + ref_count = None + elif tag in (SREF.tag, AREF.tag): + ref_name = None + ref_count = None else: stream.seek(size, io.SEEK_CUR) size, tag = Record.read_header(stream)