Skip to content

Commit d725b73

Browse files
AlecJYmrserb
authored andcommitted
8301310: The SendRawSysexMessage test may cause a JVM crash
Reviewed-by: serb
1 parent 12fce4b commit d725b73

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/java.desktop/share/native/libjsound/MidiOutDevice.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -121,6 +121,7 @@ Java_com_sun_media_sound_MidiOutDevice_nSendLongMessage(JNIEnv* e, jobject thisO
121121
jbyteArray jData, jint size, jlong timeStamp) {
122122
#if USE_PLATFORM_MIDI_OUT == TRUE
123123
UBYTE* data;
124+
UBYTE* msg;
124125
#endif
125126

126127
TRACE0("Java_com_sun_media_sound_MidiOutDevice_nSendLongMessage.\n");
@@ -133,11 +134,12 @@ Java_com_sun_media_sound_MidiOutDevice_nSendLongMessage(JNIEnv* e, jobject thisO
133134
}
134135
/* "continuation" sysex messages start with F7 (instead of F0), but
135136
are sent without the F7. */
137+
msg = data;
136138
if (data[0] == 0xF7 && size > 1) {
137-
data++;
139+
msg++;
138140
size--;
139141
}
140-
MIDI_OUT_SendLongMessage((MidiDeviceHandle*) (UINT_PTR) deviceHandle, data,
142+
MIDI_OUT_SendLongMessage((MidiDeviceHandle*) (UINT_PTR) deviceHandle, msg,
141143
(UINT32) size, (UINT32)timeStamp);
142144
// release the byte array
143145
(*e)->ReleaseByteArrayElements(e, jData, (jbyte*) data, JNI_ABORT);

test/jdk/javax/sound/midi/SysexMessage/SendRawSysexMessage.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -34,8 +34,9 @@
3434

3535
/**
3636
* @test
37-
* @bug 8237495
38-
* @summary fail with a dereferenced memory error when asked to send a raw 0xF7
37+
* @bug 8237495 8301310
38+
* @summary fail with memory errors when asked to send a sysex message starting
39+
* with 0xF7
3940
*/
4041
public final class SendRawSysexMessage {
4142

@@ -113,6 +114,16 @@ private static void test(MidiDevice.Info info) throws Exception {
113114
(byte) SPECIAL_SYSTEM_EXCLUSIVE}), -1);
114115
System.err.println("note off");
115116
r.send(new ShortMessage(ShortMessage.NOTE_OFF, 5, 5), -1);
117+
System.err.println("sysex part 1 of 3");
118+
r.send(new SysexMessage(new byte[]{
119+
(byte) SYSTEM_EXCLUSIVE, 0x7D, 0x01, 0x02}, 4), -1);
120+
System.err.println("sysex part 2 of 3");
121+
r.send(new SysexMessage(new byte[]{
122+
(byte) SPECIAL_SYSTEM_EXCLUSIVE, 0x03, 0x04}, 3), -1);
123+
System.err.println("sysex part 3 of 3");
124+
r.send(new SysexMessage(new byte[]{
125+
(byte) SPECIAL_SYSTEM_EXCLUSIVE, 0x05, 0x06, 0x07,
126+
(byte) SPECIAL_SYSTEM_EXCLUSIVE}, 4), -1);
116127
System.err.println("done, should quit");
117128
System.err.println();
118129
}

0 commit comments

Comments
 (0)