fix(tips): pad tip code payload reserved bytes with a non-zero sentinel - #523
Merged
Conversation
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.
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.
Ports Android #1163 to iOS.
Problem
The tip payload (
TipCode.Payload, kind byte2) writes a 16-byte user id at offset 1 and left the reserved trailing bytes (17–19) zero.KikCodes.decodestrips 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 sentinel1, 2, 3, so the frame always ends non-zero and round-trips at full length.Tests
reservedBytesAreZero→reservedBytesCarryFill: 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.swiftandTipCodeEncodingTests.swiftcompile clean.FlipcashTestsbundle currently fails to link onmaindue to a pre-existing, unrelated Swift 6 actor-isolation error inFlipcashTests/Regressions/Regression_69ea28b0.swift(Xcode 27), which blocked executing the suite here. Worth a separate fix.