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 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); 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..d7fbdd56 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,16 @@ 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(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()}); const auto result = old_view.toDisplayTimeForSource({42}, 0); ASSERT_FALSE(result); EXPECT_NE(result.error().find("not supported"), std::string::npos);