From 286f9e194923f8fb98859b114d17b64206d84459 Mon Sep 17 00:00:00 2001 From: jan Date: Mon, 9 Mar 2026 01:41:57 -0700 Subject: [PATCH 1/3] [read_properties] skip unrecognized tags --- klamath/elements.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/klamath/elements.py b/klamath/elements.py index 9a12b7d..c0d5567 100644 --- a/klamath/elements.py +++ b/klamath/elements.py @@ -2,6 +2,7 @@ Functionality for reading/writing elements (geometry, text labels, structure references) and associated properties. """ +import io from typing import IO, TypeVar from collections.abc import Mapping from abc import ABCMeta, abstractmethod @@ -53,6 +54,8 @@ def read_properties(stream: IO[bytes]) -> dict[int, bytes]: if key in properties: raise KlamathError(f'Duplicate property key: {key!r}') properties[key] = value + else: + stream.seek(size, io.SEEK_CUR) size, tag = Record.read_header(stream) return properties From e72b792f6f15e377e57d8e8652f7554dfc57d141 Mon Sep 17 00:00:00 2001 From: jan Date: Mon, 9 Mar 2026 01:45:06 -0700 Subject: [PATCH 2/3] [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) From 56a99c8e58a6cd0cb729454c618fc164815b7427 Mon Sep 17 00:00:00 2001 From: jan Date: Mon, 9 Mar 2026 01:52:03 -0700 Subject: [PATCH 3/3] [encode_real8] improve handling of tiny floats --- klamath/basic.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/klamath/basic.py b/klamath/basic.py index f545090..e880393 100644 --- a/klamath/basic.py +++ b/klamath/basic.py @@ -149,7 +149,7 @@ def encode_real8(fnums: NDArray[numpy.float64]) -> NDArray[numpy.uint64]: gds_exp = exp16 + 64 neg_biased = (gds_exp < 0) - gds_mant[neg_biased] >>= (gds_exp[neg_biased] * 4).astype(numpy.uint16) + gds_mant[neg_biased] >>= (-gds_exp[neg_biased] * 4).astype(numpy.uint16) gds_exp[neg_biased] = 0 too_big = (gds_exp > 0x7f) & ~(zero | subnorm) @@ -160,7 +160,6 @@ def encode_real8(fnums: NDArray[numpy.float64]) -> NDArray[numpy.uint64]: real8 = sign | gds_exp_bits | gds_mant real8[zero] = 0 - real8[gds_exp < -14] = 0 # number is too small return real8.astype(numpy.uint64, copy=False)