simon-budig / woof

an ad-hoc single file webserver
119 stars 16 forks source link

Attempting to send a file using ZIP compression crashes #3

Closed CoolCat467 closed 3 years ago

CoolCat467 commented 3 years ago

If you try to send a directory with woof using ZIP compression, woof crashes with this traceback (at least in my testing):

Now serving on http://192.168.1.200:8080/<directory name here>.zip 192.168.1.200 - - [08/Jun/2021 20:45:34] "GET /<directory name here>.zip HTTP/1.1" 200 - unexpected seek for EvilZipStreamWrapper Connection broke. Aborting Exception ignored in: <function ZipFile.__del__ at 0x7f690e446700> Traceback (most recent call last): File "/usr/lib/python3.8/zipfile.py", line 1821, in __del__ self.close() File "/usr/lib/python3.8/zipfile.py", line 1838, in close self.fp.seek(self.start_dir) File "Desktop/interwebs-woof.py", line 68, in seek raise IOError ("unexpected seek for EvilZipStreamWrapper") OSError: unexpected seek for EvilZipStreamWrapper

As you can see, the "EvilZipStreamWrapper" is getting an invalid seek value. And to be honest, looking at the code, I'm not quite sure how you'd fix it, or what purpose it serves in the first place.

CoolCat467 commented 3 years ago

Turns out if you just remove it everything works fine. Again, not quite sure what it's trying to fix. Probably silliness with the zipfile module that was likely fixed in Python3.

CoolCat467 commented 3 years ago

Oh dear I accidentally closed it 0_0

simon-budig commented 3 years ago

Thank you for your investigation.

The EvilZipStreamWrapper was necessary because the old zip module wanted to seek within the generated file to update some file headers (specifically the size of the archive IIRC). There exists a mechanism within the zip format to update this value within a data stream and this is what the wrapper was doing.

If this is no longer needed I'll gladly kill it. Although I still am a bit proud of that hack... :)

I'll look into this.

simon-budig commented 3 years ago

I have now closed this with commit 6975f6352c0b6133df4c7da344255b9966a87a77

EvilZipStreamWrapper is no more, hopefully python 3.5 is available for most woof users.