Commits

Anonymous committed c67dbc4

fix upload truncation bug on Windows

Comments (0)

Files changed (1)

hachoir-http/cgi-bin/hachoir.py

 from hachoir_core.stream.input import FileFromInputStream, InputSubStream
 from hachoir_parser.guess import guessParser
 
+# from http://code.activestate.com/recipes/273844/
+try: # Windows needs stdio set for binary mode.
+    import msvcrt
+    msvcrt.setmode (0, os.O_BINARY) # stdin  = 0
+    msvcrt.setmode (1, os.O_BINARY) # stdout = 1
+except ImportError:
+    pass
+
 # settings
 tmp_dir = 'files/'
 prune_age = 3600 # seconds
             sessid = hashlib.md5(rand).hexdigest()
         # write uploaded file
         f = open(tmp_dir+sessid+'.file','wb')
+        if form['file'].done==-1:
+            raise ValueError("File upload canceled?")
         while f.tell()<2**22: # 4MB limit
             chunk = form['file'].file.read(32768) # 32KB chunks
             if not chunk: