File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -95,10 +95,16 @@ def decode(self, encoded_packet):
9595 if q != - 1 :
9696 self .namespace = self .namespace [0 :q ]
9797 if ep and ep [0 ].isdigit ():
98- self .id = 0
99- while ep and ep [0 ].isdigit ():
100- self .id = self .id * 10 + int (ep [0 ])
101- ep = ep [1 :]
98+ i = 1
99+ end = len (ep )
100+ while i < end :
101+ if not ep [i ].isdigit () or i >= 100 :
102+ break
103+ i += 1
104+ self .id = int (ep [:i ])
105+ ep = ep [i :]
106+ if len (ep ) > 0 and ep [0 ].isdigit ():
107+ raise ValueError ('id field is too long' )
102108 if ep :
103109 self .data = self .json .loads (ep )
104110 return attachment_count
Original file line number Diff line number Diff line change @@ -157,6 +157,16 @@ def test_decode_id(self):
157157 assert pkt .id == 123
158158 assert pkt .encode () == '2123["foo"]'
159159
160+ def test_decode_id_long (self ):
161+ pkt = packet .Packet (encoded_packet = '2' + '1' * 100 + '["foo"]' )
162+ assert pkt .id == int ('1' * 100 )
163+ assert pkt .data == ['foo' ]
164+
165+ def test_decode_id_too_long (self ):
166+ with pytest .raises (ValueError ):
167+ packet .Packet (encoded_packet = '2' + '1' * 101 )
168+ packet .Packet (encoded_packet = '2' + '1' * 101 + '["foo"]' )
169+
160170 def test_encode_id_no_data (self ):
161171 pkt = packet .Packet (packet_type = packet .EVENT , id = 123 )
162172 assert pkt .id == 123
You can’t perform that action at this time.
0 commit comments