]> git.ipfire.org Git - pbs.git/commitdiff
uploads: Fix reading too much data
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 24 Oct 2022 10:42:44 +0000 (10:42 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 24 Oct 2022 10:42:44 +0000 (10:42 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/uploads.py
tests/upload.py

index 9783fe7ceffc7767236b88db7770c41c400dfe3b..349989b7a707312a4b010031456751a2256a4d54 100644 (file)
@@ -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.
index 8f3700655da48f23c03678edf545ee217a06cda6..80d38b48851bd67484846c74e2e53eaf352c3d2f 100755 (executable)
@@ -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)