From 9c4df009ee840aa3b9ad19666186f63d820cb80a Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Mon, 25 Jun 2012 03:37:42 +0200 Subject: [PATCH] Fixed bug where content-length overflowed on 32bit systems Content-Lenght could be too big for 32bit systems when uploading big files. --- servefile | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/servefile b/servefile index 05279b2..25c245b 100755 --- a/servefile +++ b/servefile @@ -483,7 +483,11 @@ class FilePutter(BaseHTTPServer.BaseHTTPRequestHandler): # write file down to disk, send an target = open(destFileName, "w") - target.write(fstorage["file"].file.read(length)) + bytesLeft = length + while bytesLeft > 0: + bytesToRead = min(1024*1024, bytesLeft) + target.write(fstorage["file"].file.read(bytesToRead)) + bytesLeft -= bytesToRead target.close() self.sendResponse(200, "OK! Thanks for uploading") print "Received file '%s' from %s." % (destFileName, self.client_address[0]) @@ -517,7 +521,11 @@ class FilePutter(BaseHTTPServer.BaseHTTPRequestHandler): self.end_headers() target = open(cleanFileName, "w") - target.write(self.rfile.read(int(self.headers['Content-Length']))) + bytesLeft = int(self.headers['Content-Length']) + while bytesLeft > 0: + bytesToRead = min(1024*1024, bytesLeft) + target.write(self.rfile.read(bytesToRead)) + bytesLeft -= bytesToRead target.close() self.sendResponse(fromPost and 200 or 201, "OK!")