Skip to content

fix(api/protocol): correct improper message payload data truncation - #153

Merged
cryptk merged 1 commit into
cryptk:mainfrom
djrobx:codex/fix-zlib-payload-boundary
Jul 31, 2026
Merged

fix(api/protocol): correct improper message payload data truncation#153
cryptk merged 1 commit into
cryptk:mainfrom
djrobx:codex/fix-zlib-payload-boundary

Conversation

@djrobx

@djrobx djrobx commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

What changed

Uses the MsgSize supplied by an OmniLogic multi-part lead message to trim reassembled response data precisely. It also removes the rstrip(b"\x00") call before zlib decompression.

Why

The previous heuristic could remove a legitimate trailing zero from a compressed stream's zlib trailer and make zlib.decompress() raise Error -5 while decompressing data: incomplete or truncated stream. The controller already reports the exact message boundary, so there is no need to guess by removing zero bytes.

zlib.decompress() tolerates trailing protocol padding after a complete stream while continuing to reject a genuinely truncated stream.

Validation

  • Captured a live controller response: its declared MsgSize exactly matched the reassembled compressed response length.
  • Added an end-to-end regression test for a compressed stream whose valid trailer ends in 0x00, followed by protocol padding.
  • pytest -q tests (full suite)
  • Ruff lint and format checks

@sonarqubecloud

sonarqubecloud Bot commented Jul 4, 2026

Copy link
Copy Markdown

@djrobx

djrobx commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

This is a Codex generated PR to address
#152

I happened to encounter the -5 condition that some others have run into.

Codex first gave a "fallback" code change that dropped down to a streaming Zlib when -5 was found that worked, but I pressed it to find a cleaner solution. Then it found MsgSize in the header, which I think is the proper fix. But, feel free to reject and re-implement as you see fit. :)

@djrobx
djrobx marked this pull request as ready for review July 4, 2026 20:27
@cryptk cryptk changed the title [codex] fix compressed response payload boundaries fix(api/protocol): correct improper message payload data truncation Jul 31, 2026
@cryptk

cryptk commented Jul 31, 2026

Copy link
Copy Markdown
Owner

This looks pretty sane, good catch! I'll try and find some time soon to get a new version of the library released and the HA integration updated.

@cryptk
cryptk merged commit 2f3691e into cryptk:main Jul 31, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants