Ticket #783 (defect)
Opened 3 months ago
Last modified 2 months ago
File uploads corrupt when using built in SSL
Status: closed (fixed)
| Reported by: | Stonekeeper | Assigned to: | fumanchu |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.1 |
| Component: | CherryPy code | Keywords: | ssl file uploads |
| Cc: |
Here is POC code:
import shutil
import os
localDir = os.path.dirname(__file__)
absDir = os.path.join(os.getcwd(), localDir)
import cherrypy
from cherrypy.lib import cptools
cherrypy.config.update({
'global': {
# 'server.ssl_certificate': 'server.pem',
# 'server.ssl_private_key': 'server.pem',
}
})
class PaperMill(object):
def index(self):
return """
<html><head></head><body>
<form id='upload_form' method='post' action='upload' enctype='multipart/form-data'>
Filename: <input id="filename_input" type="file" name="myFile"/>
<input type="submit" value="Upload!">
</form>
</body></html>"""
index.exposed = True
def upload(self, myFile):
out = """<html>
<body>
myFile length: %s<br>
myFile filename: %s<br>
myFile mime-type: %s<br>
</body>
</html>"""
size = 0
f = open("/tmp/fileupload", "wb")
while True:
data = myFile.file.read(1024 * 8) # Read blocks of 8KB at a time
if not data:
break
f.write(data)
size += len(data)
f.close()
shutil.move("/tmp/fileupload", absDir + myFile.filename)
return out % (size, myFile.filename, myFile.type)
upload.exposed = True
if __name__ == "__main__":
cherrypy.quickstart(PaperMill(),"/")
Uncomment the ssl lines and uploads will become corrupt.
Attachments
Change History
02/05/08 04:07:07: Modified by Stonekeeper
02/20/08 14:02:19: Modified by nzoschke@gmail.com
- attachment test_http_post_multipart.2.patch added.
patch for test_http.py that adds a test that exposes the ssl bug
02/20/08 14:10:50: Modified by nzoschke@gmail.com
I've been hit by this bug too. Very small posted files do not exhibit this behavior, but large ones do. The resulting file buffers are corrupted differently every time.
I attached a patch for test_http.py that exposes this error by posting a large amount of data (26 megs). I didn't do much testing to find the lower limit yet.
Occasionally the test does pass with SSL, which is curious and probably means a better test case is needed.
To see the behavior, compare:
python test.py --test_http python test.py --ssl --test_http
02/20/08 14:11:47: Modified by nzoschke@gmail.com
Should also add that test_sockets fails under ssl too...
02/20/08 14:36:03: Modified by fumanchu
- owner changed from rdelon to fumanchu.
- status changed from new to assigned.
- milestone set to 3.1.
Patch trunked in [1898].
03/09/08 00:42:04: Modified by fumanchu
Fixed in a branch in [1912].
03/12/08 01:47:20: Modified by fumanchu
- status changed from assigned to closed.
- resolution set to fixed.
Trunked in [1915].


I've done some more research on this problem. It seems that the uploaded files have about 20-ish% correct data then they become corrupt. I tried 2 different 7zip files and checked their size, difference between sizes in bytes and percentages and differences in where the file becomes corrupt. I can find no correlation. However, corruption always seems to occur on a 4 byte boundary.