Reduce payload size limit from 240 → 64 bytes#2
Merged
Conversation
… overflow) Co-authored-by: petesramek <2333452+petesramek@users.noreply.github.com> Agent-Logs-Url: https://github.com/petesramek/tiny-link/sessions/a7a7c918-f73f-48b1-bdf7-b7dcd87fe2ab
Copilot
AI
changed the title
[WIP] Fix _rawIdx overflow issue in TinyLink
Reduce payload size limit from 240 → 64 bytes
Mar 21, 2026
petesramek
approved these changes
Mar 21, 2026
…_` (#4) * Initial plan * Guard SFINAE block with #ifndef __AVR__ to fix ATtiny88 CI build Co-authored-by: petesramek <2333452+petesramek@users.noreply.github.com> Agent-Logs-Url: https://github.com/petesramek/tiny-link/sessions/c5178801-5f58-4aba-afeb-0100e94e1cbf * Updated SFINAE validation in TinyLink.h to use std::declval<T>() instead of T() for improved adapter validation. * Updated test/test_protocol.cpp with changes to tinylink::TYPE_DATA * Append missing main() function * Revert "Append missing main() function" This reverts commit bb18bb0. * fixed tesst --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: petesramek <2333452+petesramek@users.noreply.github.com> Co-authored-by: Pete Sramek <me@petesramek.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_rawIdxisuint8_t(max 255), but_rawBufisPLAIN_SIZE + 64bytes — for large payloads this exceeds 255, making the overflow guard silently unreliable. The fix enforces a 64-byte payload cap:_rawBuftops out at 133 bytes, comfortably withinuint8_trange, closing the bug without any type changes.64 bytes covers all realistic sensor + control use cases on the target Tiny88 ↔ ESP link while leaving ~310 bytes free RAM per instance on a 512-byte device.
Changes
src/TinyLink.h— tightenstatic_assertlimit and update error message:test/test_protocol.cpp— remove three tests using structs that exceed the new limit (MaxBlock235 B,Giant70 B,MaxJump230 B) and theirRUN_TESTregistrations; updatetest_protocol_mtu_limitcomment to reflect the 64-byte design ceiling.CHANGELOG.md— add entry under[Unreleased]documenting the limit reduction and the overflow fix it closes.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.registry.nm1.platformio.org/home/REDACTED/.local/bin/pio /home/REDACTED/.local/bin/pio test -e native(dns block)/home/REDACTED/.local/bin/pio /home/REDACTED/.local/bin/pio pkg install --platform native(dns block)api.registry.platformio.org/home/REDACTED/.local/bin/pio /home/REDACTED/.local/bin/pio test -e native(dns block)/home/REDACTED/.local/bin/pio /home/REDACTED/.local/bin/pio pkg install --platform native(dns block)collector.platformio.org/home/REDACTED/.local/bin/pio /home/REDACTED/.local/bin/pio test -e native(dns block)/home/REDACTED/.local/bin/pio /home/REDACTED/.local/bin/pio pkg install --platform native(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Problem
TinyLinkcurrently allows payload structs up to 240 bytes (sizeof(T) <= 240). This causes a latent bug:_rawIdxis typed asuint8_t(max 255), but_rawBufis sized asPLAIN_SIZE + 64bytes. For large payloads,sizeof(_rawBuf)can exceed 255, making the overflow guardif (_rawIdx < sizeof(_rawBuf))unreliable —_rawIdxwraps around at 255 silently before ever reaching the guard.Design Decision
TinyLink is designed as a lightweight, micro-message transport layer for resource-constrained devices like the MH-Tiny88 (512 bytes RAM) communicating with ESP boards over UART. Users define their own message structs — TinyLink is a generic skeleton, not opinionated about message content.
A 64-byte payload limit is the right constraint because:
sizeof(T) <= 64:PLAIN_SIZEmax = 69,_rawBufmax = 133 bytes — well withinuint8_trange (255), closing the_rawIdxoverflow bug as a side effect, with no type changes neededTinyLinkinstance uses ~202 bytes of RAM max, leaving ~310 bytes free on a Tiny88Changes Required
src/TinyLink.hTighten the existing
static_assertin the constructor:test/test_protocol.cppThe following tests use structs that exceed 64 bytes and must be updated or removed:
test_cobs_max_block_boundary— usesstruct MaxBlock { uint8_t raw[235]; }(235 bytes) — remove this test as it tests behavior outside the new design boundary.test_buffer_headroom_boundary— usesstruct Giant { uint8_t raw[70]; }(70 bytes) — remove this test as it exceeds the new 64-byte limit.test_cobs_max_jump_safety— usesstruct MaxJump { uint8_t data[230]; }(230 bytes) — remove this test as it exceeds the new 64-byte limit.test_protocol_mtu_limit— currently asserts3 + sizeof(TestPayload) + 2 < 256. Update the comment to reflect the new 64-byte limit. The assert itself can stay as a sanity check but update the comment:main()— removeRUN_TEST(test_cobs_max_block_boundary),RUN_TEST(test_buffer_headroom_boundary), andRUN_TEST(test_cobs_max_jump_safety)from themain()test runner.README.mdUpdate any mention of the 240-byte payload limit to reflect the new 64-byte limit. Search for "240" in the README and update accordingly.
CHANGELOG.mdAdd an entry to the
[Unreleased]section:The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Hey, I would like you to review the repository and make assessment.
Assistant: Here is a comprehensive assessment of petesramek/tiny-link:
📋 Repository Assessment:
petesramek/tiny-link🏁 Overview
TinyLink is a well-crafted, header-only C++ library (v0.4.0) implementing a lightweight serial communication protocol over UART. It is clearly purpose-built for resource-constrained microcontrollers. The project is in an early but polished state, showing strong engineering fundamentals.
✅ Strengths
🔧 Core Protocol Design
0x00, and Fletcher-16 provides far stronger error detection than a plain checksum — detecting both bit-flips and swapped bytes.memcpyinto a fixed_datafield, and a raw function pointer callback (void(*)(const T&)) keep RAM usage predictable.static_assertguards for payload size (≤ 240 bytes) and alignment (alignof(T) == 1) provide excellent early-error DX.📦 Architecture & Portability
tinylinknamespace prevents collision with other libraries, which is import...This pull request was created from Copilot chat.
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.