-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Conversation
… offset for the dictionary
👋 Welcome back lancea! A progress list of the required criteria for merging this PR into |
@LanceAndersen The following label will be automatically applied to this pull request: 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 |
Webrevs
|
There was a problem hiding this 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)); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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.
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>: |
Minor updates have been made to the tests |
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. |
I have made additional updates to testByteBufferDirect to incorporate your suggestions |
There was a problem hiding this 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.
There was a problem hiding this 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.
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.
I updated the test name(s).
Addressed the issues above. I have pushed the updated changes for review to the PR. |
There was a problem hiding this 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.
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. |
There was a problem hiding this 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.
@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:
Since the source branch of this PR was last updated there have been 190 commits pushed to the
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 ➡️ To integrate this PR with the above commit message to the |
/integrate |
@LanceAndersen Since your change was applied there have been 190 commits pushed to the
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. |
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
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/269/head:pull/269
$ git checkout pull/269