Skip to content

fix(tips): pad tip code payload reserved bytes with a non-zero sentinel - #523

Merged
bmc08gt merged 3 commits into
mainfrom
fix/tip-payload-padding
Jul 27, 2026
Merged

fix(tips): pad tip code payload reserved bytes with a non-zero sentinel#523
bmc08gt merged 3 commits into
mainfrom
fix/tip-payload-padding

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Ports Android #1163 to iOS.

Problem

The tip payload (TipCode.Payload, kind byte 2) writes a 16-byte user id at offset 1 and left the reserved trailing bytes (17–19) zero. KikCodes.decode strips trailing zero bytes, so a frame whose reserved region (or user-id tail) is zero comes back short.

iOS already handled this defensively on the decode side (re-padding the frame before reading). This change also fixes it on the encode side for full-length frame parity with Android and any consumer that doesn't re-pad.

Fix

  • encode() fills the reserved region (offset 17 onward) with an incrementing non-zero sentinel 1, 2, 3, so the frame always ends non-zero and round-trips at full length.
  • The decoder's re-pad is kept — still correct for legacy zero-trailing frames.

Tests

  • reservedBytesAreZeroreservedBytesCarryFill: asserts bytes 17–19 == 1, 2, 3.
  • decodesAZeroStrippedFrame: reworked to reconstruct a legacy zero-reserved frame explicitly (the encoder no longer ends in zeros), so it still exercises the decoder's restore path.

Testing

  • TipCode.Payload+Encoding.swift and TipCodeEncodingTests.swift compile clean.
  • Note: the FlipcashTests bundle currently fails to link on main due to a pre-existing, unrelated Swift 6 actor-isolation error in FlipcashTests/Regressions/Regression_69ea28b0.swift (Xcode 27), which blocked executing the suite here. Worth a separate fix.

The tip payload left the reserved trailing bytes (17-19) zero. KikCodes.decode
strips trailing zero bytes, so a frame whose reserved region (or user id tail)
is zero comes back short. Fill the reserved region with incrementing digits
(1, 2, 3) on encode so the frame always ends non-zero and round-trips at full
length. Decoding still re-pads for legacy zero-trailing frames. Mirrors
Android #1163.
* origin/main:
  fix(tests): restore FlipcashTests compilation under Xcode 27 main-actor isolation (#526)
  chore(tips): remove profile photo from tip card setup for now (#522)
  feat(tips): open post-tip chats with the keyboard up (#524)
  feat(tips): use the minimized send button only in tip chats (#525)
@bmc08gt bmc08gt self-assigned this Jul 27, 2026
…payload branch

The #524 (focusOnAppear) and #525 (isTipDm) conversation-bar params were
integrated on main without a separator between them, leaving
ConversationScreen and ChatScreenRepresentable non-compiling. Add the missing
commas so the tree builds.
@bmc08gt
bmc08gt merged commit 3000fdd into main Jul 27, 2026
@bmc08gt
bmc08gt deleted the fix/tip-payload-padding branch July 27, 2026 21:09
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.

1 participant