Преглед изворни кода

Fix crash if the data is split between CR and LF

master
JustAnotherArchivist пре 3 година
родитељ
комит
68c577bc92
1 измењених фајлова са 4 додато и 4 уклоњено
  1. +4
    -4
      irclog.py

+ 4
- 4
irclog.py Прегледај датотеку

@@ -326,15 +326,15 @@ class IRCClientProtocol(asyncio.Protocol):
def data_received(self, data):
time_ = time.time()
self.logger.debug(f'Data received: {data!r}')
# Split received data on CRLF. If there's any data left in the buffer, prepend it to the first message and process that.
# If there's any data left in the buffer, prepend it to the data. Split on CRLF.
# Then, process all messages except the last one (since data might not end on a CRLF) and keep the remainder in the buffer.
# If data does end with CRLF, all messages will have been processed and the buffer will be empty again.
messages = data.split(b'\r\n')
if self.buffer:
messages[0] = self.buffer + messages[0]
data = self.buffer + data
messages = data.split(b'\r\n')
for message in messages[:-1]:
lines = self.server.recv(message + b'\r\n')
assert len(lines) == 1
assert len(lines) == 1, f'recv did not return exactly one line: {message!r} -> {lines!r}'
self.message_received(time_, message, lines[0])
self.server.parse_tokens(lines[0])
self.buffer = messages[-1]


Loading…
Откажи
Сачувај