Repository navigation
refuse to encode a 1033 frame the package cannot parse - #588
Closed
aashish254 wants to merge 1 commit into
Closed
aashish254 wants to merge 1 commit into
aashish254 wants to merge 1 commit into
Conversation
Contributor
|
@leoleovich has imported this pull request. If you are a Meta employee, you can view this in D126438243. |
Contributor
|
@leoleovich merged this pull request in beb208d. |
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.
rtcm.Encode1033takes anAntennaDescriptorof caller-supplied strings and writes their lengths intothe frame without checking either width limit the format imposes. Two consequences on main, both measured:
The payload can exceed the 10-bit length field. The header is preamble + 6 reserved zero bits + a
10-bit length (
MaxPayloadLen = 1023), butpayloadSizeis built straight fromlen(desc.*)and thenwritten with
binary.BigEndian.PutUint16(frame[1:3], uint16(len(payload)&0xFFFF)). With five 250-bytedescriptor fields the encoder returns a 1265-byte frame whose header reads
d3 04 eb:0x4sits in thereserved bits (
frame[1] & 0xFC == 0x4) and the length the rest of the package reads back is 235, not 1259.The same package then rejects its own output:
So
ntripper, which injects a 1033 on connect and every 30s, would hand a caster a frame its own scannercan't even resynchronise past.
A descriptor string longer than 255 bytes silently lies about itself. DF227/DF230/DF232/DF234/DF236 are
8-bit counters, and the encoder writes
uint8(len(...)). For a 300-byteAntennaTypethe frame declares a44-byte field, so a conformant parser reads 44 bytes and treats the remaining 256 as the next fields —
corrupt payload, valid CRC, no error anywhere on the read path.
What changed
Encode1033now returns([]byte, error)and rejects both cases up front:ErrDescriptorTooLong(new)for a string over
maxDescriptorFieldLen,ErrPayloadTooLarge(already the package's word for exactlythis, raised by
ParseFrameatrtcm.go:93and bymsm_encode.go:548) for a total that doesn't fit theheader. This matches how
msm_encode.goalready signals the same class of overflow instead of emitting aframe the parser rejects.
frame[1] = len>>8 & 0x03) so thereserved bits can't be loaded again. To be clear, this line is equivalent to
PutUint16for everylength the guards now allow, so it isn't a second fix — it just makes the invariant the old line broke
visible where it broke.
cmd/ntripper/streamFrames) wraps the error, and the existing test call sites gothrough a
mustEncode1033helper.Verification
TestEncode1033RejectsUnrepresentableFramescovers both rejection paths, including a case whereevery field is individually legal but their sum is not.
TestEncode1033LargestRepresentableFramebuilds the longest frame the header can still describe(255+255+255+249 descriptor bytes + 9 bytes overhead = exactly
MaxPayloadLen), asserts the reserved bitsstay zero, and round-trips it through both
ParseFrameandNewScanner— the encoder and the package'sown readers now agree at the boundary.
10-bit header length" subtest, deleting the per-field loop fails only "field exceeds its 8-bit counter".
Neither guard is carried by the other.
go test -count=1 ./rtcm/... ./cmd/ntripper/...,go test -race ./rtcm/... ./cmd/ntripper/...,go vet,gofmt -landgolangci-lint run(repo.golangci.yml) all clean.