fix: Handle TCP segmentation in SLK file transitions#3925
Merged
Conversation
Fixed CheckStreamStatus() to request additional data when the file-segment mask arrives but the next file's metadata (filename + filesize) hasn't been received yet due to TCP segmentation.
Contributor
Author
Tracking
Standard development
CI Testing Labels
Documentation checklist
|
|
andrejtonev
approved these changes
Mar 24, 2026
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.




What
Fix a bug in SLK stream processing where TCP segmentation during file transitions caused
CheckStreamStatusto incorrectly returnNEW_FILEinstead ofPARTIAL. The fix adds metadata completeness validationin
CheckStreamStatus()(src/slk/streams.cpp) when akFileSegmentMaskis encountered during a file transition (i.e.,remaining_file_sizeis set), ensuring the full file metadata (filename string + filesize uint) is present before signaling the transition.
Why
When the SLK protocol transitions between files in a multi-file transfer, the sender emits
kFileSegmentMaskfollowed by the new file's metadata (filename + size). TCP can split the segment boundary such thatthe mask arrives in one packet but the metadata arrives later. Without this fix, the
OpenFilepath in the Reader would attempt to parse incomplete metadata and fail with "Size data missing in SLK stream!".How
In
CheckStreamStatus, whenkFileSegmentMaskis encountered andremaining_file_sizeis set (indicating a file-to-file transition, not the first file), the code now performs a two-stage check beforereturning
NEW_FILE:If either check fails,
PARTIALis returned with the appropriatestream_sizehint so the caller knows how much more data to wait for. The check is gated onremaining_file_sizebeing set, so first-filedetection is unaffected.
Testing
Added 5 unit tests in
tests/unit/slk_streams.cpp:FileTransitionMaskOnly— mask present but zero metadata bytes; expectsPARTIALFileTransitionPartialStringPrefix— fewer than 9 bytes after mask; expectsPARTIALFileTransitionPartialStringData— string prefix present but string body truncated; expectsPARTIALFileTransitionSufficientMetadata— complete metadata present; expectsNEW_FILE(positive case)FirstFileMaskNotAffectedByCheck— noremaining_file_size; verifies the new guard doesn't regress first-file detectionNotes for reviewers
stream_sizevalues returned in thePARTIALbranches are best-effort hints (pos + kSegmentMaxTotalSizewhen the string length is unknown,pos + neededwhen it is). Verify these are sufficient forthe caller's read-more logic.
str_len <= kSegmentMaxDataSizeprotects against corrupted length fields — if the length is impossibly large, the code falls through to the existingNEW_FILEreturn, which will let the Readersurface a more specific error during actual parsing