Skip to content

i_1227 Workaround ZipStreamer zero length file bug#1257

Merged
johnbrvc merged 2 commits into
i1006_point_scoringfrom
i1227_ZipStreamer_Exception
May 27, 2026
Merged

i_1227 Workaround ZipStreamer zero length file bug#1257
johnbrvc merged 2 commits into
i1006_point_scoringfrom
i1227_ZipStreamer_Exception

Conversation

@johnbrvc
Copy link
Copy Markdown
Collaborator

@johnbrvc johnbrvc commented Apr 14, 2026

Description of what the PR does

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, 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:

i_1227\
   13706813.zip - The Kattis submission that aggravates the original issue
           (it contains 2 files, one OK, the other is zero length)
   hello.java - copy of the samps/src/hello.java - really a dummy placeholder as you'll see
   pc2submit - special version of the Python pc2submit command that will use the
            Kattis submission zip (above) instead of making a new zip.
  1. Start a clean contest using the pointscoring sample contest.
  2. Start an administrator1 client.
  3. Add a single team account using the Generate button on the Accounts tab.
  4. On the administrator Settings tab , scroll all the way down to the Remote CCS Settings and check the Enable CCS Test Mode box.
  5. Start the feeder1 event feeder client.
  6. Start the contest on the administrator Times tab, press Start All.
  7. Extract the attached zip file, preserving the structure described above. The zip expects to be extracted into /tmp (\tmp), since the custom pc2submit in the zip has a hardcoded path. If you use a different folder, you'll have to update the pc2submit extracted from the zip to use whatever path you extracted to.
  8. Create a command prompt and change to the extracted i_1227 folder.
  9. Execute the following command:
    py pc2submit -y -p a hello.java -t 1 -u https://administrator1:administrator1@localhost:50443
    The hello.java program 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 supplied 13706813.zip Kattis file which contains a zero length file.
  10. You should get an error back that says: Submission failed (code 400 - submission source files are empty)
C:\tmp\i_1227>py pc2submit -y -p a hello.java -t 1 -u https://administrator1:administrator1@localhost:50443
Warning: 'hello.java' has not been modified for 1118226 minutes!
Submission information:
  filename:    hello.java
  contest:     pointscoring
  problem:     A
  language:    Java
  url:         https://administrator1:administrator1@localhost:50443/
There are warnings for this submission!
Submission failed (code 400 - submission source files are empty)
  1. If you want to set a breakpoint and trace through the new code, in pc2/convert/EventFeedUtilities.java, set it at line 198.

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 .netrc contains the following:
machine localhost login administrator1 password administrator1
The PR author will not provide assistance in tracking down credential errors, firewall issues or other "user related" problems on your system.

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(;;) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@SamanwaySadhu
Copy link
Copy Markdown
Collaborator

Code changes look good. Works as described. Few things to address:
1> Add steps in the PR to update pc2submit file in the i_1227.zip as certain paths are hardcoded and one may not extract them in a way the file expects. (Not a blocker for approval)
2> Either fix the failing CI builds or provide explanation if this PR is ready for approval without the all the JUnits succeeding. (Blocker for approval)

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.
@johnbrvc
Copy link
Copy Markdown
Collaborator Author

Code changes look good. Works as described. Few things to address: 1> Add steps in the PR to update pc2submit file in the i_1227.zip as certain paths are hardcoded and one may not extract them in a way the file expects. (Not a blocker for approval) 2> Either fix the failing CI builds or provide explanation if this PR is ready for approval without the all the JUnits succeeding. (Blocker for approval)

  1. I updated the PR instructions.
  2. Since the "point scoring" related PR's are going to a branch (i1006_point_scoring) and not develop, we don't want to change the Junits to work with point scoring because it will break them when we merge back into develop. The Junit's will be fixed when we finally merge the i1006_point_scoring branch into develop AFTER WF50. The failing Junits are related to differences introduced by point scoring changes, and I do check them to be sure they're "OK".

@SamanwaySadhu SamanwaySadhu self-requested a review May 13, 2026 21:43
Copy link
Copy Markdown
Collaborator

@SamanwaySadhu SamanwaySadhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

@clevengr clevengr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@johnbrvc johnbrvc merged commit 0301bd0 into i1006_point_scoring May 27, 2026
2 of 3 checks passed
@johnbrvc johnbrvc deleted the i1227_ZipStreamer_Exception branch May 27, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants