Undefined Behavior Sanitizer flags MIDIPacket advanced with MIDIPacketNext() for misaligned pointer use

Number:rdar://37363662 Date Originated:02/08/2018
Status:Open Resolved:
Product:macOS SDK Product Version:10.13.3
Classification:Other Bug Reproducible:Always

The Undefined Behavior Sanitizer flags member access of a MIDIPacket* returned by MIDIPacketNext() on Intel.

Steps to Reproduce:

1. Compile the attached program with UBSan turned on using:

clang -std=c99 -framework CoreMIDI -fsanitize=undefined MIDIPacketNextTest.m

2. Run the program:


Expected results:

The program runs fine.

Actual results:

MIDIPacketNextTest.m:32:15: runtime error: member access within misaligned address 0x7f83626006e3 for type 'MIDIPacket' (aka 'struct MIDIPacket'), which requires 4 byte alignment

UBSan flags the if (packet->length == 0) expression for misaligned pointer use noting that MIDIPacket requires 4-byte alignment. This is contrary to the comment in MIDIPacketNext() itself, as well as the header documentation for MIDIPacketList, which says: "On Intel and PowerPC, MIDIPacket is unaligned. On ARM, MIDIPacket must be 4-byte aligned."

Xcode Version 9.2 (9C40b), macOS 10.13.2 (17C205)

Test Program: https://gist.github.com/armadsen/424a5427f77cb25c5abca6c7ce21564b


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!