From e5ee0016e49c29168af1302e61e09db26f1c10ce Mon Sep 17 00:00:00 2001 From: Davide Faconti Date: Mon, 16 Nov 2026 06:00:09 +0100 Subject: [PATCH 1/4] fix(parser_module): stop the test byte writers shifting a uint64_t by 64 The aliased-scalar-names helpers in parser_module_abi_test and the native parser module fixture write each field byte as value >> (8 * index), and put(3, 0, 17) reaches index 8. UBSan aborts both tests in PlotJuggler's ASan + UBSan lane: "shift exponent 64 is too large for 64-bit type 'uint64_t'". Bytes past the eighth are now written as zero, which is what the descriptor expects there. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019HWZVLrTWPNZoqhipSkDAk --- .../parser_module/tests/native_parser_module_fixture.cpp | 2 +- experimental/parser_module/tests/parser_module_abi_test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/experimental/parser_module/tests/native_parser_module_fixture.cpp b/experimental/parser_module/tests/native_parser_module_fixture.cpp index 905bc7d0..4cbbaf01 100644 --- a/experimental/parser_module/tests/native_parser_module_fixture.cpp +++ b/experimental/parser_module/tests/native_parser_module_fixture.cpp @@ -108,7 +108,7 @@ void writeAliasedScalarNames(std::vector& output) { output.assign(kNameOffset + kNameBytes, uint8_t{'n'}); const auto put = [&output](size_t at, uint64_t value, size_t width) { for (size_t index = 0; index < width; ++index) { - output[at + index] = static_cast(value >> (8U * index)); + output[at + index] = static_cast(index < sizeof(value) ? value >> (8U * index) : 0U); } }; put(0, PJ_MODULE_OUTPUT_DESCRIPTOR_VERSION_V1, 2); diff --git a/experimental/parser_module/tests/parser_module_abi_test.cpp b/experimental/parser_module/tests/parser_module_abi_test.cpp index 209c12fb..50f61125 100644 --- a/experimental/parser_module/tests/parser_module_abi_test.cpp +++ b/experimental/parser_module/tests/parser_module_abi_test.cpp @@ -289,7 +289,7 @@ std::vector aliasedScalarOutput(size_t field_count, size_t name_bytes) std::vector block(name_offset + name_bytes, uint8_t{'n'}); const auto put = [&block](size_t at, uint64_t value, size_t width) { for (size_t index = 0; index < width; ++index) { - block[at + index] = static_cast(value >> (8U * index)); + block[at + index] = static_cast(index < sizeof(value) ? value >> (8U * index) : 0U); } }; put(0, PJ_MODULE_OUTPUT_DESCRIPTOR_VERSION_V1, 2); From 73c57f90d4fc3d8451c59fd75a5716ac37dfc477 Mon Sep 17 00:00:00 2001 From: Davide Faconti Date: Mon, 16 Nov 2026 06:00:10 +0100 Subject: [PATCH 2/4] fix(pj_base): build truncated test vtables as whole objects with a poisoned tail TooSmallStructSizeIsUnbound allocated only the bytes struct_size claims and read them through PJ_mcp_endpoint_host_vtable_t, an object too small for its type. UBSan's object-size check aborts mcp_endpoint_host_test in PlotJuggler's ASan + UBSan lane: "member access within address ... with insufficient space for an object of type 'const PJ_mcp_endpoint_host_vtable_t'". The test now allocates a whole vtable and ASan-poisons everything past struct_size, so a slot read made before checking struct_size is still caught (use-after-poison; checked by dropping the struct_size check from McpEndpointHostView::valid()). PlaybackApiTest.SourceConversionIsOptionalOnLegacyHosts builds its legacy vtable the same way and passes today only because the optimizer hides the allocation size; it gets the same change. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019HWZVLrTWPNZoqhipSkDAk --- pj_base/tests/mcp_endpoint_host_test.cpp | 23 ++++++++++++-------- pj_base/tests/playback_viewport_api_test.cpp | 22 ++++++++++++------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/pj_base/tests/mcp_endpoint_host_test.cpp b/pj_base/tests/mcp_endpoint_host_test.cpp index 6d8143f5..dc401a28 100644 --- a/pj_base/tests/mcp_endpoint_host_test.cpp +++ b/pj_base/tests/mcp_endpoint_host_test.cpp @@ -4,7 +4,6 @@ #include #include -#include #include #include #include @@ -15,6 +14,12 @@ #include "pj_base/sdk/service_traits.hpp" #include "pj_base/sdk/testing/fake_mcp_endpoint_host.hpp" +#if __has_include() +#include // ASAN_POISON_MEMORY_REGION, a no-op without ASan +#else +#define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size)) +#endif + namespace PJ { namespace { @@ -131,15 +136,15 @@ TEST(McpEndpointHostView, TooSmallStructSizeIsUnbound) { FakeMcpEndpointHost host; const PJ_mcp_endpoint_host_t full = host.makeHost(); - // The allocation ends where release_endpoint would start, so ASAN catches a - // slot read made before checking struct_size. + // Everything from release_endpoint on is poisoned, so ASAN catches a slot read + // made before checking struct_size. The allocation stays a whole vtable: one cut + // short there is too small for the type the view reads it through, which + // UBSan's object-size check reports at the struct_size read itself. constexpr auto short_size = offsetof(PJ_mcp_endpoint_host_vtable_t, release_endpoint); - PJ_mcp_endpoint_host_vtable_t declared = *full.vtable; - declared.struct_size = short_size; - auto truncated = std::make_unique(short_size); - std::memcpy(truncated.get(), &declared, short_size); - const sdk::McpEndpointHostView view( - PJ_mcp_endpoint_host_t{&host, reinterpret_cast(truncated.get())}); + auto truncated = std::make_unique(*full.vtable); + truncated->struct_size = short_size; + ASAN_POISON_MEMORY_REGION(reinterpret_cast(truncated.get()) + short_size, sizeof(*truncated) - short_size); + const sdk::McpEndpointHostView view(PJ_mcp_endpoint_host_t{&host, truncated.get()}); EXPECT_FALSE(view.valid()); EXPECT_FALSE(view.acquire()); diff --git a/pj_base/tests/playback_viewport_api_test.cpp b/pj_base/tests/playback_viewport_api_test.cpp index 96c0289c..6d15abd5 100644 --- a/pj_base/tests/playback_viewport_api_test.cpp +++ b/pj_base/tests/playback_viewport_api_test.cpp @@ -4,13 +4,18 @@ #include #include -#include #include #include #include "pj_base/plugin_data_api.h" #include "pj_base/sdk/plugin_data_api.hpp" +#if __has_include() +#include // ASAN_POISON_MEMORY_REGION, a no-op without ASan +#else +#define ASAN_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size)) +#endif + namespace PJ { namespace { @@ -252,14 +257,15 @@ TEST(PlaybackApiTest, SourceConversionIsOptionalOnLegacyHosts) { EXPECT_FALSE(view.toDisplayTimeForSource({42}, 0)); EXPECT_TRUE(view.toDisplayTime("topic", 0)); - // The allocation ends at the legacy vtable boundary, so ASAN detects a tail - // read performed before checking struct_size. + // Everything past the legacy vtable boundary is poisoned, so ASAN detects a + // tail read performed before checking struct_size. The allocation stays a whole + // vtable: one cut short there is too small for the type the view reads it + // through, which UBSan's object-size check reports at the struct_size read. constexpr auto legacy_size = offsetof(PJ_playback_host_vtable_t, to_display_time_for_source); - vtable.struct_size = legacy_size; - auto legacy = std::make_unique(legacy_size); - std::memcpy(legacy.get(), &vtable, legacy_size); - const sdk::PlaybackHostView old_view( - PJ_playback_host_t{.ctx = &host, .vtable = reinterpret_cast(legacy.get())}); + auto legacy = std::make_unique(vtable); + legacy->struct_size = legacy_size; + ASAN_POISON_MEMORY_REGION(reinterpret_cast(legacy.get()) + legacy_size, sizeof(*legacy) - legacy_size); + const sdk::PlaybackHostView old_view(PJ_playback_host_t{.ctx = &host, .vtable = legacy.get()}); const auto result = old_view.toDisplayTimeForSource({42}, 0); ASSERT_FALSE(result); EXPECT_NE(result.error().find("not supported"), std::string::npos); From c2a30c6473518f7aa36e6cac4905e127ae4e43b6 Mon Sep 17 00:00:00 2001 From: Davide Faconti Date: Mon, 16 Nov 2026 20:18:28 +0100 Subject: [PATCH 3/4] chore(release): 1.0.1 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019HWZVLrTWPNZoqhipSkDAk --- CHANGELOG.md | 10 ++++++++++ VERSION | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c6bd627..178087d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,16 @@ All notable changes to `plotjuggler_sdk` are recorded here. Versioning policy is in [`CLAUDE.md`](./CLAUDE.md) → "Release Versioning". +## [1.0.1] + +Host contract: unchanged (no floor impact). +Test-only release: the SDK's own tests no longer have undefined behaviour under UBSan, so +PlotJuggler's ASan + UBSan lane, which builds them from the release sources, can run them. The +byte writers of `parser_module_abi_test` and the native parser module fixture no longer shift a +`uint64_t` by 64, and `mcp_endpoint_host_test` and `PlaybackApiTest` build truncated vtables as +whole objects with an ASan-poisoned tail instead of reading through a too-small allocation. +Libraries and headers are unchanged from 1.0.0. + ## [1.0.0] Host contract: extended: builtin object types kMeshMap (21) and kMeshMapUpdate (22) (floor 1.0.0). diff --git a/VERSION b/VERSION index 3eefcb9d..7dea76ed 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 +1.0.1 From 4d5cf37040da54dcb7f9311f2f87d104298274b6 Mon Sep 17 00:00:00 2001 From: Davide Faconti Date: Mon, 16 Nov 2026 20:25:22 +0100 Subject: [PATCH 4/4] test(pj_base): give the legacy playback vtable a set slot The truncated legacy vtable copied the one whose to_display_time_for_source was already null, so without ASan the struct_size check was never needed for the assertion to hold. It now starts from a full vtable: only struct_size hides the slot, so a view reading it unchecked fails in every build. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_019HWZVLrTWPNZoqhipSkDAk --- pj_base/tests/playback_viewport_api_test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pj_base/tests/playback_viewport_api_test.cpp b/pj_base/tests/playback_viewport_api_test.cpp index 6d15abd5..d7fbdd56 100644 --- a/pj_base/tests/playback_viewport_api_test.cpp +++ b/pj_base/tests/playback_viewport_api_test.cpp @@ -262,7 +262,8 @@ TEST(PlaybackApiTest, SourceConversionIsOptionalOnLegacyHosts) { // vtable: one cut short there is too small for the type the view reads it // through, which UBSan's object-size check reports at the struct_size read. constexpr auto legacy_size = offsetof(PJ_playback_host_vtable_t, to_display_time_for_source); - auto legacy = std::make_unique(vtable); + auto legacy = + std::make_unique(makePlaybackVtable()); // slot set: only struct_size hides it legacy->struct_size = legacy_size; ASAN_POISON_MEMORY_REGION(reinterpret_cast(legacy.get()) + legacy_size, sizeof(*legacy) - legacy_size); const sdk::PlaybackHostView old_view(PJ_playback_host_t{.ctx = &host, .vtable = legacy.get()});