Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void writeAliasedScalarNames(std::vector<uint8_t>& 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<uint8_t>(value >> (8U * index));
output[at + index] = static_cast<uint8_t>(index < sizeof(value) ? value >> (8U * index) : 0U);
}
};
put(0, PJ_MODULE_OUTPUT_DESCRIPTOR_VERSION_V1, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ std::vector<uint8_t> aliasedScalarOutput(size_t field_count, size_t name_bytes)
std::vector<uint8_t> 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<uint8_t>(value >> (8U * index));
block[at + index] = static_cast<uint8_t>(index < sizeof(value) ? value >> (8U * index) : 0U);
}
};
put(0, PJ_MODULE_OUTPUT_DESCRIPTOR_VERSION_V1, 2);
Expand Down
23 changes: 14 additions & 9 deletions pj_base/tests/mcp_endpoint_host_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <gtest/gtest.h>

#include <cstddef>
#include <cstring>
#include <memory>
#include <string>
#include <string_view>
Expand All @@ -15,6 +14,12 @@
#include "pj_base/sdk/service_traits.hpp"
#include "pj_base/sdk/testing/fake_mcp_endpoint_host.hpp"

#if __has_include(<sanitizer/asan_interface.h>)
#include <sanitizer/asan_interface.h> // 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 {

Expand Down Expand Up @@ -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<unsigned char[]>(short_size);
std::memcpy(truncated.get(), &declared, short_size);
const sdk::McpEndpointHostView view(
PJ_mcp_endpoint_host_t{&host, reinterpret_cast<const PJ_mcp_endpoint_host_vtable_t*>(truncated.get())});
auto truncated = std::make_unique<PJ_mcp_endpoint_host_vtable_t>(*full.vtable);
truncated->struct_size = short_size;
ASAN_POISON_MEMORY_REGION(reinterpret_cast<char*>(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());
Expand Down
23 changes: 15 additions & 8 deletions pj_base/tests/playback_viewport_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
#include <gtest/gtest.h>

#include <cstdint>
#include <cstring>
#include <memory>
#include <string>

#include "pj_base/plugin_data_api.h"
#include "pj_base/sdk/plugin_data_api.hpp"

#if __has_include(<sanitizer/asan_interface.h>)
#include <sanitizer/asan_interface.h> // 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 {

Expand Down Expand Up @@ -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<unsigned char[]>(legacy_size);
std::memcpy(legacy.get(), &vtable, legacy_size);
const sdk::PlaybackHostView old_view(
PJ_playback_host_t{.ctx = &host, .vtable = reinterpret_cast<const PJ_playback_host_vtable_t*>(legacy.get())});
auto legacy =
std::make_unique<PJ_playback_host_vtable_t>(makePlaybackVtable()); // slot set: only struct_size hides it
legacy->struct_size = legacy_size;
ASAN_POISON_MEMORY_REGION(reinterpret_cast<char*>(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);
Expand Down
Loading