mrkkrp / zip

Efficient library for manipulating zip archives
Other
81 stars 27 forks source link

withArchive takes very long to detect illegal archive #16

Closed hce closed 8 years ago

hce commented 8 years ago

Using withArchive on a file that is not a valid archive can take a lot of time and CPU and before an error is thrown. It would be nice if illegal files were detected immediately.

For example, create a file using dd: dd bs=1k count=10k if=/dev/urandom of=invalid.zip

And then do: withArchive pathToInvalidZip $ return ()

mrkkrp commented 8 years ago

Thank you for the report, I will look into that this weekend.

mrkkrp commented 8 years ago

@hce, Should be fixed, please check locally if you can. There will be one more change and I'll reseale new version on Hackage.

hce commented 8 years ago

Just tested it: it takes less than a second now. Thank you!

mrkkrp commented 8 years ago

We cannot make it faster because we should assume that comment may be up to 0xffff bytes long (archive ends with a comment “field” and to scan it fast we need to traverse from end backwards till we hit end of central directory signature).

Glad it works!