JDK-8319315 : Sending a SysexMessage starting with 0xF7 leads to JVM crash
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 17,21,22
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2023-10-25
  • Updated: 2023-11-08
  • Resolved: 2023-11-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
i7-12700H / Windows 11 22H2 / OpenJDK 22-ea+20
i7-12700H / OpenSUSE Tumbleweed / OpenJDK 22-ea+20

A DESCRIPTION OF THE PROBLEM :
SysexMessage allows splitting a sysex message into multiple SysexMessage. The first SysexMessage will start with 0xF0. Other continuing  SysexMessage will start with 0xF7. A SysexMessage starting with 0xF0 can be send by javax.sound.midi.Receiver normally. However, attempting to send a SysexMessage starting with 0xF7 results in a JVM crash.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
First, make sure there is at least one MIDI output device provided by OS, such as "Microsoft GS Wavetable Synth" in Windows or the "snd_virmidi" kernel module in Linux.

Second, split a sysex message into at least two SysexMessage and send to the MIDI output device.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The MIDI device received the sysex message.
ACTUAL -
On Windows, JVM crashes without any error messages.

On Linux, JVM crashes with the following error message
free(): invalid pointer
Aborted (core dumped)

---------- BEGIN SOURCE ----------
import javax.sound.midi.*;

public class SysexTest {
    public static void main(String[] args) {
        var deviceInfos = MidiSystem.getMidiDeviceInfo();
        for (var info : deviceInfos) {
            try (MidiDevice device = MidiSystem.getMidiDevice(info)) {
                if (device.getMaxReceivers() != 0) {
                    System.out.println("Open MIDI port: " + info.getName());
                    device.open();
                    Receiver receiver = device.getReceiver();
                    try {
                        // Send (F0 7D 01 02), (03 04), (05 06 F7) separately
                        receiver.send(new SysexMessage(new byte[]{(byte) 0xF0, 0x7D, 0x01, 0x02}, 4), -1);
                        receiver.send(new SysexMessage(new byte[]{(byte) 0xF7, 0x03, 0x04}, 3), -1);
                        receiver.send(new SysexMessage(new byte[]{(byte) 0xF7, 0x05, 0x06, (byte) 0xF7}, 4), -1);
                        System.out.println("All SysexMessage sent");
                    } catch (InvalidMidiDataException e) {
                        e.printStackTrace();
                    }
                }
            } catch (MidiUnavailableException e) {
                e.printStackTrace();
            }
        }
    }
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Additional Information from submitter: =============================== It appears that JVM crashed when testing on Windows 11. The console output should have messages after "Open MIDI port: Microsoft MIDI Mapper", such as "All SysexMessage sent" if the SysexMessage was sent successfully or printing stack trace if an exception occurred. However, there are no messages following "Open MIDI port: Microsoft MIDI Mapper". On the other hand, JVM didn't crash when running on Ubuntu 20.04 because the two MIDI devices "Gervill" and "Real Time Sequencer" are provided by JVM. Trying to add a virtual MIDI device with the command `sudo modprobe snd_virmidi midi_devs=1` should reproduce the bug.
06-11-2023

Checked with attached testcase in Windows 11, Did not observe, JVM Crash. Console Output Windows 11 D:\Incidents\JI-9076158>javac SysexTest.java D:\Incidents\JI-9076158>java SysexTest Open MIDI port: Gervill All SysexMessage sent Open MIDI port: Real Time Sequencer All SysexMessage sent Open MIDI port: Microsoft MIDI Mapper D:\Incidents\JI-9076158> Console output in Ubuntu 20.04 -------------------------------------------- dcspn@dcspn-VirtualBox:~/incident_triage/JI-9076158$ javac SysexTest.java dcspn@dcspn-VirtualBox:~/incident_triage/JI-9076158$ java SysexTest Open MIDI port: Gervill All SysexMessage sent Open MIDI port: Real Time Sequencer All SysexMessage sent dcspn@dcspn-VirtualBox:~/incident_triage/JI-9076158$
02-11-2023