Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8321156: Improve the handling of invalid UTF-8 byte sequences for ZipInputStream::getNextEntry and ZipFile::getComment #17995

Closed
wants to merge 5 commits into from

Conversation

LanceAndersen
Copy link
Contributor

@LanceAndersen LanceAndersen commented Feb 24, 2024

Please review this PR which addresses the handling of invalid UTF-8 byte sequences in the entry name of a LOC file header and a Zip file comment which is returned via ZipFile::getComment.

As part of the change, ZipFile::getComment will now return null if an invalid UTF-8 byte sequence is encountered while converting the byte array to a String. The CSR for this change has also been approved.

Mach5 tiers 1-3 are clean with this change.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change requires CSR request JDK-8321927 to be approved
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issues

  • JDK-8321156: Improve the handling of invalid UTF-8 byte sequences for ZipInputStream::getNextEntry and ZipFile::getComment (Bug - P4)
  • JDK-8321927: Uncaught exceptions when parsing ZIP files with certain entry names or comments (CSR)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/17995/head:pull/17995
$ git checkout pull/17995

Update a local copy of the PR:
$ git checkout pull/17995
$ git pull https://git.openjdk.org/jdk.git pull/17995/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 17995

View PR using the GUI difftool:
$ git pr show -t 17995

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/17995.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 24, 2024

👋 Welcome back lancea! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 24, 2024
@openjdk
Copy link

openjdk bot commented Feb 24, 2024

@LanceAndersen The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Feb 24, 2024
@mlbridge
Copy link

mlbridge bot commented Feb 24, 2024

Webrevs

Copy link
Contributor

@eirbjo eirbjo left a comment

Choose a reason for hiding this comment

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

Left a few comment on the code changes and the test. Some may be a matter of preference.

@eirbjo
Copy link
Contributor

eirbjo commented Feb 24, 2024

Since the CSR is already approved, I'll add a question here:

ZipFile performs a lot of validation while opening ZIP files, including throwning ZipException for invalid entry names or comments. Why handle the ZIP file comment differently (lazily)? If this comment was also validated by the constructor, then the API change for ZipFile::getComment would not be needed.

Do we have reason to belive the encoding quality of ZIP file comments is less reliable than that of ZIP entry comments? Or is there some other reason this validation is done lazily?

Copy link
Contributor Author

@LanceAndersen LanceAndersen left a comment

Choose a reason for hiding this comment

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

Thank you for your input Eirik, I have pushed updates to address the suggestions you raised

@LanceAndersen
Copy link
Contributor Author

Since the CSR is already approved, I'll add a question here:

ZipFile performs a lot of validation while opening ZIP files, including throwning ZipException for invalid entry names or comments. Why handle the ZIP file comment differently (lazily)? If this comment was also validated by the constructor, then the API change for ZipFile::getComment would not be needed.

Do we have reason to belive the encoding quality of ZIP file comments is less reliable than that of ZIP entry comments? Or is there some other reason this validation is done lazily?

Yes, there are some libraries/tools that are using the Zip file comment for its own purposes such as idea_rt.jar which is part of IntelliJ.

Copy link
Member

@jaikiran jaikiran left a comment

Choose a reason for hiding this comment

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

Hello Lance, the changes look fine to me. ZipFile.java file will need a copyright year update.

@openjdk
Copy link

openjdk bot commented Feb 25, 2024

@LanceAndersen This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8321156: Improve the handling of invalid UTF-8 byte sequences for ZipInputStream::getNextEntry and ZipFile::getComment

Reviewed-by: jpai, alanb

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 3 new commits pushed to the master branch:

  • 1799ffe: 8310351: Typo in ImmutableCollections
  • d10f277: 8326006: Allow TEST_VM_FLAGLESS to set flagless mode
  • 63f6a56: 8326530: Widen allowable error bound of Math.tan

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 25, 2024
Comment on lines 523 to 524
} catch(Exception ex) {
throw (ZipException) new ZipException(
Copy link
Contributor

Choose a reason for hiding this comment

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

Whitespace nit:

Suggested change
} catch(Exception ex) {
throw (ZipException) new ZipException(
} catch (Exception ex) {
throw (ZipException) new ZipException(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor Author

@LanceAndersen LanceAndersen left a comment

Choose a reason for hiding this comment

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

Thanks for the feedback. Updated accordingly

Comment on lines 523 to 524
} catch(Exception ex) {
throw (ZipException) new ZipException(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@LanceAndersen
Copy link
Contributor Author

Hello Lance, the changes look fine to me. ZipFile.java file will need a copyright year update.

Thank you Jai, updated

Copy link
Member

@jaikiran jaikiran left a comment

Choose a reason for hiding this comment

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

Thank you for the updates, Lance. The changes look good to me.

* Returns the zip file comment, or null if none.
* Returns the zip file comment. If a comment does not exist or an error is
* encountered decoding the comment using the charset specified
* when opening the Zip file, then {@code null} is returned.
Copy link
Contributor

Choose a reason for hiding this comment

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

I've previously discussed options with Lance around this issue and I agree with the proposal to specify that it returns null when the decoding fails.

(In passing, the casing of "zip file" is very inconsistent in the javadoc, it's "ZIP file" in some places, "zip file" in others, the change here uses "Zip file").

Copy link
Contributor Author

@LanceAndersen LanceAndersen Feb 25, 2024

Choose a reason for hiding this comment

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

(In passing, the casing of "zip file" is very inconsistent in the javadoc, it's "ZIP file" in some places, "zip file" in others, the change here uses "Zip file").

Thank you for pointing out the discrepancy above.

Let's decide on which way to go and I will update under a separate PR.

I would suggest "ZIP file" based on the PKWare APPNOTE.TXT, but the man pages for info-zip command zip command uses "zip file"

Apache commons also uses "ZIP file" or "ZIP archive"

Copy link
Member

Choose a reason for hiding this comment

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

I would suggest "ZIP file" based on the PKWare APPNOTE.TXT,

I think using this case would be good.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest "ZIP file" based on the PKWare APPNOTE.TXT, but the man pages for info-zip command zip command uses "zip file"

"ZIP" is not an acronym so I assume this is why they use "zip" in their docs.

Copy link
Contributor

@AlanBateman AlanBateman left a comment

Choose a reason for hiding this comment

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

Spec + implementation change look fine. I haven't spent time looking at the test.

@LanceAndersen
Copy link
Contributor Author

/integrate

1 similar comment
@LanceAndersen
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Feb 26, 2024

Going to push as commit 20c71ce.
Since your change was applied there have been 9 commits pushed to the master branch:

  • c042f08: 8326653: Remove jdk.internal.reflect.UTF8
  • bb6b048: 8326099: GZIPOutputStream should use Deflater.getBytesRead() instead of Deflater.getTotalIn()
  • 490825f: 8325589: C2 SuperWord refactoring: create VLoopAnalyzer with Submodules
  • 3a00fc7: 8323698: Class use page does not include extends/implements type arguments
  • f32f574: 8326575: Remove unused ContiguousSpace::set_top_for_allocations
  • 09f755a: 8325857: G1 Full GC flushes mark stats cache too early
  • 1799ffe: 8310351: Typo in ImmutableCollections
  • d10f277: 8326006: Allow TEST_VM_FLAGLESS to set flagless mode
  • 63f6a56: 8326530: Widen allowable error bound of Math.tan

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Feb 26, 2024
@openjdk openjdk bot closed this Feb 26, 2024
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Feb 26, 2024
@openjdk openjdk bot removed the rfr Pull request is ready for review label Feb 26, 2024
@openjdk
Copy link

openjdk bot commented Feb 26, 2024

@LanceAndersen Pushed as commit 20c71ce.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@openjdk
Copy link

openjdk bot commented Feb 26, 2024

@LanceAndersen The command integrate can only be used in open pull requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants