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

8252739: Deflater.setDictionary(byte[], int off, int len) ignores the starting offset for the dictionary #269

Closed
wants to merge 5 commits into from

Conversation

LanceAndersen
Copy link
Contributor

@LanceAndersen LanceAndersen commented Sep 20, 2020

Hi all,

Please review the fix for JDK-8252739 which addresses an issue introduced by https://bugs.openjdk.java.net/browse/JDK-8225189, where Deflater.c ignored the offset specified by Deflater.setDictionary.

Mach5 jdk-tier1, jdk-tier2, jdk-tier3 runs cleanly as well as the java/util/zip and java/util/jar JCK tests.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8252739: Deflater.setDictionary(byte[], int off, int len) ignores the starting offset for the dictionary

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/269/head:pull/269
$ git checkout pull/269

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 20, 2020

👋 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
Copy link

openjdk bot commented Sep 20, 2020

@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 (add|remove) "label" command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Sep 20, 2020
@LanceAndersen LanceAndersen changed the title RFR 8252739: Deflater.setDictionary(byte[], int off, int len) ignores the starting offset for the dictionary 8252739: Deflater.setDictionary(byte[], int off, int len) ignores the starting offset for the dictionary Sep 20, 2020
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 20, 2020
@mlbridge
Copy link

mlbridge bot commented Sep 20, 2020

Webrevs

Copy link
Member

@uschindler uschindler left a comment

Choose a reason for hiding this comment

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

The tests with byte buffers (direct and heap) are not using offsets (arrayOffset=0). The direct buffer test uses just a series of 0-bytes, so incorrect offsets won't change result. There should be real data copied into the direct buffer.

byte[] input = SRC_DATA.getBytes(UTF_8);
byte[] output = new byte[RESULT_SIZE];
// Compress the bytes
ByteBuffer dictDef = ByteBuffer.wrap(DICTIONARY.getBytes(UTF_8));
Copy link
Member

Choose a reason for hiding this comment

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

This should use a slice of the byte buffer, so array offset is not 0. This can be done with offset and size on the wrap() call.

byte[] input = SRC_DATA.getBytes(UTF_8);
byte[] output = new byte[RESULT_SIZE];
// Compress the bytes
ByteBuffer dictDef = ByteBuffer.allocateDirect(DICTIONARY.length());
Copy link
Member

Choose a reason for hiding this comment

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

This creates an empty dictionary with only 0 bytes. Maybe copy some real data into the buffer. Also a slice should be used.

@mlbridge
Copy link

mlbridge bot commented Sep 20, 2020

Mailing list message from Uwe Schindler on core-libs-dev:

Hi,

I left some comments on the PR.

The tests with ByteBuffers are not testing the bug correctly.

Uwe

Am September 20, 2020 6:14:59 PM UTC schrieb Lance Andersen <lancea at openjdk.java.net>:

@LanceAndersen
Copy link
Contributor Author

Minor updates have been made to the tests

@uschindler
Copy link
Member

uschindler commented Sep 20, 2020

Ok much better for the heap buffers. Many thanks.

The direct buffers have now contents, but I think it should copy the whole heap array into the byte buffer. After that set position and limit and then call slice(). After that you have a slice of the original direct buffer with offset.

@LanceAndersen
Copy link
Contributor Author

I have made additional updates to testByteBufferDirect to incorporate your suggestions

Copy link
Member

@uschindler uschindler left a comment

Choose a reason for hiding this comment

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

Looks fine to me.

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.

Update to Deflater.c looks good.

DeflaterDictionaryTests looks like is a shaping up to be a good test for setDictionary. Are there other assertions that should be checked, e.g. setDictionary(ByteBuffer) is specified to consume all bytes and it would be good to check that the position is set to the limit. Also can the 2-arg setDictionary be tests, also corner cases such no bytes remaining or invoked with null.

The naming of the tests is a bit inconsistent, e.g. ByteArrayTest vs. testByteBufferDirect. In the naming then I would use "Heap" instead of "Wrap", as in testHeapByteBuffer.

In passing: The tests can use try-finally to ensure that Deflater::end is invoked even when the test fails. String repeat(int) could be used to avoid duplicating "Welcome to Us Open;". Missing space in several "if(...)" usages.

@LanceAndersen
Copy link
Contributor Author

LanceAndersen commented Sep 21, 2020

Update to Deflater.c looks good.

DeflaterDictionaryTests looks like is a shaping up to be a good test for setDictionary. Are there other assertions that should be checked, e.g. setDictionary(ByteBuffer) is specified to consume all bytes and it would be good to check that the position is set to the limit. Also can the 2-arg setDictionary be tests, also corner cases such no bytes remaining or invoked with null.

I have logged JDK-8253444 to add more coverage for setDictionary. I would prefer to put this change back to address the offset not being used and improve the coverage afterwards.

The naming of the tests is a bit inconsistent, e.g. ByteArrayTest vs. testByteBufferDirect. In the naming then I would use "Heap" instead of "Wrap", as in testHeapByteBuffer.

I updated the test name(s).

In passing: The tests can use try-finally to ensure that Deflater::end is invoked even when the test fails. String repeat(int) could be used to avoid duplicating "Welcome to Us Open;". Missing space in several "if(...)" usages.

Addressed the issues above.

I have pushed the updated changes for review to the PR.

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.

Given that the offset handling is buggy then I think the test should at least cover the cases where the offset is 0 or out of bounds. No problem separating out further test coverage for the other setDictionary methods into a separate issue.

@LanceAndersen
Copy link
Contributor Author

Given that the offset handling is buggy then I think the test should at least cover the cases where the offset is 0 or out of bounds. No problem separating out further test coverage for the other setDictionary methods into a separate issue.

I updated the test to include an offset test for 0 and to add a test for out of range offsets. I have updated the PR.

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.

Thanks for update to cover the offset 0 and out of bound cases.

@openjdk
Copy link

openjdk bot commented Sep 23, 2020

@LanceAndersen This change now passes all automated pre-integration checks. In addition to the automated checks, the change must also fulfill all project specific requirements

After integration, the commit message will be:

8252739: Deflater.setDictionary(byte[], int off, int len) ignores the starting offset for the dictionary

Reviewed-by: uschindler, alanb
  • If you would like to add a summary, use the /summary command.
  • To credit additional contributors, use the /contributor command.
  • To add additional solved issues, use the /issue command.

Since the source branch of this PR was last updated there have been 190 commits pushed to the master branch:

  • 5f1d612: 8253397: Ensure LogTag types are sorted
  • b8ea80a: 8253457: Remove unimplemented register stack functions
  • e4d0e5a: 8253516: ZGC: Remove card table functions
  • 3fe5886: 8252696: Loop unswitching may cause out of bound array load to be executed
  • 226faa5: 8253241: Update comment on java_suspend_self_with_safepoint_check()
  • bd67975: 8253349: Remove unimplemented SharedRuntime::native_method_throw_unsupported_operation_exception_entry
  • bddb822: 8253240: No javadoc for DecimalFormatSymbols.hashCode()
  • c68a31d: 8253499: Problem list runtime/cds/DeterministicDump.java
  • 93a2018: 8252195: AWT Accessibility API nested classes rely on default constructors
  • 426c904: 8253392: remove PhaseCCP_DCE declaration
  • ... and 180 more: https://git.openjdk.java.net/jdk/compare/4b3a0b789ebf389a9589c9af2d3922fb91916d92...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid automatic rebasing, please merge master into your branch, and then specify the current head hash when integrating, like this: /integrate 5f1d6120a531cedcd0cb33568e04f79c649d0788.

➡️ 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 Sep 23, 2020
@LanceAndersen
Copy link
Contributor Author

/integrate

@openjdk openjdk bot closed this Sep 23, 2020
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 23, 2020
@openjdk
Copy link

openjdk bot commented Sep 23, 2020

@LanceAndersen Since your change was applied there have been 190 commits pushed to the master branch:

  • 5f1d612: 8253397: Ensure LogTag types are sorted
  • b8ea80a: 8253457: Remove unimplemented register stack functions
  • e4d0e5a: 8253516: ZGC: Remove card table functions
  • 3fe5886: 8252696: Loop unswitching may cause out of bound array load to be executed
  • 226faa5: 8253241: Update comment on java_suspend_self_with_safepoint_check()
  • bd67975: 8253349: Remove unimplemented SharedRuntime::native_method_throw_unsupported_operation_exception_entry
  • bddb822: 8253240: No javadoc for DecimalFormatSymbols.hashCode()
  • c68a31d: 8253499: Problem list runtime/cds/DeterministicDump.java
  • 93a2018: 8252195: AWT Accessibility API nested classes rely on default constructors
  • 426c904: 8253392: remove PhaseCCP_DCE declaration
  • ... and 180 more: https://git.openjdk.java.net/jdk/compare/4b3a0b789ebf389a9589c9af2d3922fb91916d92...master

Your commit was automatically rebased without conflicts.

Pushed as commit 812b39f.

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

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.

3 participants