From 7531feecb70af491d978bf07b37c6c0748931201 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Mon, 13 May 2019 11:24:09 +0300 Subject: [PATCH] Correctly handle newline detection not only for open boundary but for close mark too (#3758) --- aiohttp/multipart.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/aiohttp/multipart.py b/aiohttp/multipart.py index dd6bb245bed..eb56ab9ca65 100644 --- a/aiohttp/multipart.py +++ b/aiohttp/multipart.py @@ -647,15 +647,22 @@ async def _read_until_first_boundary(self) -> None: if chunk == b'': raise ValueError("Could not find starting boundary %r" % (self._boundary)) - if chunk.startswith(self._boundary): + newline = None + end_boundary = self._boundary + b'--' + if chunk.startswith(end_boundary): + _, newline = chunk.split(end_boundary, 1) + elif chunk.startswith(self._boundary): _, newline = chunk.split(self._boundary, 1) - assert newline in (b'\r\n', b'\n') + if newline is not None: + assert newline in (b'\r\n', b'\n'), (newline, + chunk, + self._boundary) self._newline = newline chunk = chunk.rstrip() if chunk == self._boundary: return - elif chunk == self._boundary + b'--': + elif chunk == end_boundary: self._at_eof = True return