Skip to content

Commit 921049d

Browse files
authored
Merge pull request #83 from semuconsulting/RC-1.1.8
RC 1.1.8
2 parents 023eeb6 + 669e395 commit 921049d

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

RELEASE_NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# pyrtcm Release Notes
22

3+
### RELEASE 1.1.8
4+
5+
1. Address issue [#82](https://github.com/semuconsulting/pyrtcm/issues/82).
6+
37
### RELEASE 1.1.7
48

59
1. Internal streamlining of RTCMReader - no functional changes.

src/pyrtcm/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
:license: BSD 3-Clause
99
"""
1010

11-
__version__ = "1.1.7"
11+
__version__ = "1.1.8"

src/pyrtcm/rtcmreader.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,13 @@ def _parse_rtcm3(self, hdr: bytes) -> tuple:
159159
:param bytes hdr: first 2 bytes of RTCM3 header
160160
:return: tuple of (raw_data as bytes, parsed_stub as RTCMMessage)
161161
:rtype: tuple
162+
:raises: RTCMStreamError
162163
"""
163164

164165
hdr3 = self._read_bytes(1)
165166
size = (hdr[1] << 8) | hdr3[0]
167+
if size == 0:
168+
raise RTCMStreamError(f"Invalid payload size {size} bytes")
166169
payload = self._read_bytes(size)
167170
crc = self._read_bytes(3)
168171
raw_data = hdr + hdr3 + payload + crc

tests/test_stream.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,41 @@ def testBADHDR_IGNORE(self): # invalid header in data with quitonerror = 0
549549
for raw, parsed in ubr:
550550
i += 1
551551

552+
def testZeroLengthPayload(self):
553+
DATA = (
554+
b"\xd3\x00\x15>\xe0\x00\x03\x84\x1a\x86\x92\xbf\xb4KK\xf4\xfa\xb7\xdc7b\x8a\x01W\x1b\xa9\xd6"
555+
b"\xd3\x00\x00>\xf0\x00\x14SEPCHOKE_B3E6 SPKE\x00\x07nf"
556+
b"\xd3\x00\x1e?\x00\x00\x14SEPCHOKE_B3E6 SPKE\x00\x045856\xffh\x94"
557+
)
558+
559+
with BytesIO(DATA) as stream:
560+
with self.assertRaisesRegex(
561+
RTCMStreamError, "Invalid payload size 0 bytes"
562+
):
563+
ubr = RTCMReader(stream, quitonerror=ERR_RAISE)
564+
for raw, parsed in ubr:
565+
print(parsed)
566+
567+
def testZeroLengthPayloadIgnore(self):
568+
DATA = (
569+
b"\xd3\x00\x15>\xe0\x00\x03\x84\x1a\x86\x92\xbf\xb4KK\xf4\xfa\xb7\xdc7b\x8a\x01W\x1b\xa9\xd6"
570+
b"\xd3\x00\x00>\xf0\x00\x14SEPCHOKE_B3E6 SPKE\x00\x07nf"
571+
b"\xd3\x00\x1e?\x00\x00\x14SEPCHOKE_B3E6 SPKE\x00\x045856\xffh\x94"
572+
)
573+
EXPECTED_RESULT = [
574+
"<RTCM(1006, DF002=1006, DF003=0, DF021=0, DF022=1, DF023=1, DF024=1, DF141=0, DF025=1762489.6191, DF142=1, DF001_1=0, DF026=-5027633.8438, DF364=2, DF027=-3496008.8438000004, DF028=0.034300000000000004)>",
575+
# "Invalid payload size 0 bytes",
576+
"<RTCM(1008, DF002=1008, DF003=0, DF029=20, DF030_01=S, DF030_02=E, DF030_03=P, DF030_04=C, DF030_05=H, DF030_06=O, DF030_07=K, DF030_08=E, DF030_09=_, DF030_10=B, DF030_11=3, DF030_12=E, DF030_13=6, DF030_14= , DF030_15= , DF030_16= , DF030_17=S, DF030_18=P, DF030_19=K, DF030_20=E, DF031=0, DF032=4, DF033_01=5, DF033_02=8, DF033_03=5, DF033_04=6)>",
577+
]
578+
with BytesIO(DATA) as stream:
579+
ubr = RTCMReader(stream, quitonerror=ERR_LOG)
580+
i = 0
581+
for raw, parsed in ubr:
582+
print(f'"{parsed}",')
583+
self.assertEqual(str(parsed), EXPECTED_RESULT[i])
584+
i += 1
585+
self.assertEqual(i, 2)
586+
552587

553588
if __name__ == "__main__":
554589
# import sys;sys.argv = ['', 'Test.testName']

0 commit comments

Comments
 (0)