i_1227 Workaround ZipStreamer zero length file bug#1257
Conversation
Catch the ZipException caused by reading a zip file that has a zero length file in it. We look at the error message string generated by the ZipStreamer in the ZipException. If it is the error message of interest, ignore it, and return with whatever files have been accumulated so far.
| while ((bytesRead = zipStream.read(buffer)) != -1) | ||
| { | ||
| byteOutputStream.write(buffer, 0, bytesRead); | ||
| for(;;) { |
There was a problem hiding this comment.
Whenever dealing with infinite loops there should be an additional counter-based break point for safety (even though in practice it "may" never execute infinitely).
There was a problem hiding this comment.
I don't think that's necessary in this case. There is no "can't happen" scenario here. There are 2 ways out of the "infinite" loop. When we read the last entry in the zip file (getNextEntry() returns null), or, there's an unexpected exception, in which case we "throw" our way out. That being said, it is not unreasonable to put an upper limit on the max number of entries to read from the zip file, which is what I did. Fix in most recent push.
|
Code changes look good. Works as described. Few things to address: |
We put a reasonable limit (1000 currently) on the max entries allowed in a zip file (for submissions). This will prevent us from dealing with an unreasonable submission.
|
clevengr
left a comment
There was a problem hiding this comment.
I reviewed the code changes; everything seems reasonable. I ran the tests suggested in the PR, and after working around some issues I was able to verify the code works as intended.
I had a couple of minor issues where the PR Test Steps didn't quite work; I updated those steps to clarify the situation in case other developers attempt to following them.
Kudos for providing the "special Kattis zip file"; that made testing a WHOLE LOT EASIER!
I approve the PR.
Description of what the PR does
Catch the
ZipExceptioncaused by reading a zip file that has a zero length file in it. We look at the error message string generated by theZipStreamerin theZipException. If it is the error message of interest, eg. "only DEFLATED entries can have EXT descriptor", ignore it, and return with whatever files have been accumulated so far. Any other error will cause an exception as it did previously.The issue, #1227 has a description of what is going on and a reference to a Stack Overflow article describing it. This PR simply works around this problem.
Issue which the PR addresses
Fixes #1227
Fixes #1217
Environment in which the PR was developed (OS,IDE, Java version, etc.)
java version "1.8.0_321"
Java(TM) SE Runtime Environment (build 1.8.0_321-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.321-b07, mixed mode)
Precise steps for testing the PR (i.e., how to demonstrate that it works correctly)
The attached zip file, i_1227.zip, contains files the allows you to test this PR in the quickest way possible (without replaying an entire Kattis contest). The zip file contains the following structure:
/tmp(\tmp), since the custompc2submitin the zip has a hardcoded path. If you use a different folder, you'll have to update thepc2submitextracted from the zip to use whatever path you extracted to.i_1227folder.py pc2submit -y -p a hello.java -t 1 -u https://administrator1:administrator1@localhost:50443The
hello.javaprogram is a dummy to satisfy the requirement of supplying a source code file. In reality, the special version of pc2submit ignores this file, and simply submits the supplied13706813.zipKattis file which contains a zero length file.If the pc2submit command complains about bad credentials or other connection nonsense, you will have to diagnose that yourself. The credential information on Windows is kept in
\users\USERNAME\.netrc. My.netrccontains the following:machine localhost login administrator1 password administrator1The PR author will not provide assistance in tracking down credential errors, firewall issues or other "user related" problems on your system.