From: Michael Tremer Date: Mon, 24 Oct 2022 10:42:44 +0000 (+0000) Subject: uploads: Fix reading too much data X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=20781e0987eaccb25178cb3a1cd919bb4420c4a4;p=pbs.git uploads: Fix reading too much data Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/uploads.py b/src/buildservice/uploads.py index 9783fe7c..349989b7 100644 --- a/src/buildservice/uploads.py +++ b/src/buildservice/uploads.py @@ -251,6 +251,10 @@ class Upload(base.DataObject): with open(self.path, "wb") as dst: shutil.copyfileobj(src, dst) + # Check that we didn't copy too much + if dst.tell() > self.size: + raise OverflowError + async def copyinto(self, dst): """ Copies the content of this upload into the destination file descriptor. diff --git a/tests/upload.py b/tests/upload.py index 8f370065..80d38b48 100755 --- a/tests/upload.py +++ b/tests/upload.py @@ -36,7 +36,7 @@ class UploadTestCase(test.TestCase): """ Creates an upload of a certain size, but then tries to write more data """ - payload = io.BytesIO(b"01234567890123456789") + payload = io.BytesIO(b"012345678901234567890123456789") with self.db.transaction(): upload = self.backend.uploads.create("test.blob", size=20, user=self.user)