From 99d74a5bbcf5f19af5d4c587e319511e30fd4411 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Mon, 9 Nov 2026 00:10:06 +0900 Subject: [PATCH 1/2] fix(python): a channel token with a NUL character is refused CableDyn_EvalChannel reads a token up to its first NUL, so CableDyn.channel passed "FairTen1\0x" through and returned FairTen1, and a token starting with a NUL came back as a library error about an empty token. The binding now refuses a token holding a NUL with a ValueError before calling the library, as it already does for a deck path. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 2 ++ python/cabledyn/objects.py | 3 +++ python/tests/test_objects.py | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3549554..1804e7b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ All notable changes to CableDyn are recorded in this file. The format follows The touchdown element now takes the reaction of its grounded stretch, from the grounded node to the touchdown point located from the two nodes' clearances: the error falls at the second order (2.1, 0.7, 0.2 N) and the outputs vary continuously. +- Python: `CableDyn.channel` and `channels` refuse a token holding a NUL character, which the + library read only up to the NUL (`"FairTen1\0x"` returned `FairTen1`). ## [0.4.1] - 2026-11-08 diff --git a/python/cabledyn/objects.py b/python/cabledyn/objects.py index 12a8c0b3..083e25b3 100644 --- a/python/cabledyn/objects.py +++ b/python/cabledyn/objects.py @@ -494,6 +494,9 @@ def eval_channel(model: CableDyn, token: str) -> float: """Evaluate one OUTPUTS token (the caller holds the model lock).""" if not isinstance(token, str): raise TypeError(f"channel token must be a string; got {type(token).__name__}") + if "\0" in token: + # the library ends a token at its first NUL, so "FairTen1\0x" would read as FairTen1 + raise ValueError(f"channel token must not contain a NUL character; got {token!r}") try: raw = token.strip().encode("ascii") except UnicodeEncodeError: diff --git a/python/tests/test_objects.py b/python/tests/test_objects.py index 6486fc45..99de88b4 100644 --- a/python/tests/test_objects.py +++ b/python/tests/test_objects.py @@ -562,6 +562,16 @@ def test_channel_tokens_must_be_ascii(tmp_path): model.channel("FairTen\u00b91") +@pytest.mark.parametrize("token", ["FairTen1\x00", "FairTen1\x00x", "\x00FairTen1"]) +def test_channel_tokens_must_not_hold_a_nul(tmp_path, token): + # the library reads a token up to its first NUL: "FairTen1\0x" would read as FairTen1 + with CableDyn(_held_chain(tmp_path)) as model: + with pytest.raises(ValueError, match="NUL"): + model.channel(token) + with pytest.raises(ValueError, match="NUL"): + model.channels(["FairTen1", token]) + + def test_zero_length_rod_axis_is_a_value_error(tmp_path, monkeypatch): deck = _write(tmp_path, "rod.dat", _ROD_DECK) with CableDyn(deck) as model: From 9e1a7bf688484df3168ec70f2728d951a16e2039 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Mon, 9 Nov 2026 00:29:51 +0900 Subject: [PATCH 2/2] chore(changelog): the entry moves to the batch changelog change The [Unreleased] entries of the open changes are added together in one change, so that they do not conflict with each other. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1804e7b8..e3549554 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,8 +18,6 @@ All notable changes to CableDyn are recorded in this file. The format follows The touchdown element now takes the reaction of its grounded stretch, from the grounded node to the touchdown point located from the two nodes' clearances: the error falls at the second order (2.1, 0.7, 0.2 N) and the outputs vary continuously. -- Python: `CableDyn.channel` and `channels` refuse a token holding a NUL character, which the - library read only up to the NUL (`"FairTen1\0x"` returned `FairTen1`). ## [0.4.1] - 2026-11-08