-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8282578: AIOOBE in javax.sound.sampled.Clip #9016
Conversation
Surround SysEx message processing block with try/catch allowing MIDI subsystem to attempt to ingest the rest of the file. Added test case.
👋 Welcome back kizune! A progress list of the required criteria for merging this PR into |
@azuev-java 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 /label pull request command. |
Webrevs
|
Probably it is better to check the data length for each sys message and discard it if the data is too small? Ignoring all possible AIOOBE from this large method which calls many other large methods from SoftVoice/SoftTuning may hide some other bugs. |
@azuev-java 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:
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 201 new 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 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 |
No, because determining the correct length of the message will require basically to parse it all, the correct length could be a 2 bytes or hundreds of bytes - in order to determine we have to process the message completely. |
There are 64 usages of |
@azuev-java This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
pre submit tests failed* |
@azuev-java This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
@azuev-java This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |
Just uploaded the new version with proper length analysis so would be thankful for the continuation of the review. |
/open |
@azuev-java This pull request is now open |
@azvegint Can you please take a look? |
int subid2 = data[4] & 0xFF; | ||
switch (subid2) { | ||
case 0x01: // BULK TUNING DUMP (NON-REAL-TIME) | ||
{ | ||
// http://www.midi.org/about-midi/tuning.shtml | ||
//if (!checksumOK2(data)) | ||
// break; | ||
if (data.length < 406) { |
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.
At first glance it looks like a magic numbers to me.
for better readability we could declare r
before this check and use 128*3 + r
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.
Makes sense, fixed.
int ll = data[6] & 0xFF; | ||
if (data.length < ll * 4 + 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.
Shouldn't it be ll * 4 + 7
== ll * 4 + r
?
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.
Yes.
@@ -193,6 +228,9 @@ public void load(byte[] data) { | |||
// Real-Time/REAL-TIME) | |||
{ | |||
// http://www.midi.org/about-midi/tuning-scale.shtml | |||
if (data.length < 21) { |
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.
< 20
?
int[] data = new int[20];
for (int i = 0; i < 12; i++) {
System.out.println(data[i + 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.
Yes. Math is hard.
int[] ranges = new int[(data.length - 7) / 2]; | ||
int ix = 0; | ||
for (int j = 6; j < data.length - 1; j += 2) { | ||
destinations[ix] = data[j] & 0xFF; |
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.
Here is another possible AIOOOBE
e.g. if data
length is 8, we will have destination
and ranges
length of 0:
int[] data = new int[8];
System.out.println("data len " + data.length);
if (data.length < 7) {
System.out.println("Prevent");
return;
}
int newSize = (data.length - 7) / 2;
System.out.println("new size " + newSize);
int[] destinations = new int[newSize];
int[] ranges = new int[newSize];
int ix = 0;
for (int j = 6; j < data.length - 1; j += 2) {
System.out.println("index %d %d".formatted(j, ix) );
destinations[ix] = data[j] & 0xFF;
System.out.println("index " + (j + 1));
ranges[ix] = data[j + 1] & 0xFF;
ix++;
}
Same applies to similar cases below.
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.
Ok, i think there are 3 places total with this possibility when increment goes by 2 so fixed them all.
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.
Length check won't help here:
int[] data = new int[100];
if (data.length < 8) {
return;
}
int[] destinations = new int[(data.length - 7) / 2];
int[] ranges = new int[(data.length - 7) / 2];
int ix = 0;
for (int j = 6; j < data.length - 1; j += 2) {
destinations[ix] = data[j] & 0xFF;
ranges[ix] = data[j + 1] & 0xFF;
ix++;
}
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 46 out of bounds for length 46
We might want to add more test cases to the test.
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.
Length check won't help here:
I think the problem here is in the original code: the array allocation was reused across 3 places and it reserved buffers for ranges and destinations that should load up the remaining of data from the offset 7, but in first two places are trying to load data from offset 6, which causes buffer overflow. The idea of my new fix here is to create a proper buffers.
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.
We might want to add more test cases to the test.
That would be an extensive task, there is a set of the tests being run by third party - and that's them who created the initial issue. I do not think it is practical to bring all the cases they test here. That testing takes a very long time.
|
||
case 0x0A: // Key Based Instrument Control | ||
{ | ||
if (data.length < 7 || (data[4] & 0xFF) != 01) { |
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.
Neat: 0x01
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.
Ok.
break; | ||
} | ||
default: | ||
break; | ||
// http://www.midi.org/about-midi/tuning_extens.shtml |
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.
Unrelated to change, but looks like those links become unavailable years ago.
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.
Yes. That's the problem referencing the external site for information. Unfortunately the documentation layout on midi site changed and one needs to read trough all of it to figure out the correct path that both relates to the midi-1.0 standard that we support and is not overwritten by some later addendum making it non-informative.
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.
We might want to track this under some issue, if not done already.
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.
Created JDK-8298319 to track this issue.
/integrate |
Going to push as commit af8fb7e.
Your commit was automatically rebased without conflicts. |
@azuev-java Pushed as commit af8fb7e. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Thank you for removing that large try/catch block. Looks much better. |
I agree, the code is clearer now. I started reviewing the updated code but I haven't finished it. It's integrated now. |
Add try/catch clause to ignore an exception since it is harmless for we isolated
the massge data before passing it ro processor.
Add test case.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/9016/head:pull/9016
$ git checkout pull/9016
Update a local copy of the PR:
$ git checkout pull/9016
$ git pull https://git.openjdk.org/jdk pull/9016/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 9016
View PR using the GUI difftool:
$ git pr show -t 9016
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/9016.diff