[go: up one dir, main page]

Skip to content
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

Copy packets to prevent AddressSanitizer: stack-use-after-return on address #2911

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

kirsteins
Copy link
Contributor

Enabling the "Address Sanitizer" with the "Detect use of stack after return" feature has exposed a stack-use-after-return issue in the following code example:

import AudioKit
import CoreMIDI

private func createTestMIDIPacketList() -> MIDIPacketList {
    let midiData: [UInt8] = [0x90, 60, 90]
    let packetListPointer = UnsafeMutablePointer<MIDIPacketList>.allocate(capacity: 1)
    var packet = MIDIPacketListInit(packetListPointer)
    let timeStamp: MIDITimeStamp = 0
    packet = MIDIPacketListAdd(packetListPointer, 512, packet, timeStamp, midiData.count, midiData)
    return packetListPointer.pointee
}

func triggerAddressSanitizerWithUseOfStackAfterReturn() {
    for packet in createTestMIDIPacketList() {
        // Accesses packet via iterator and cause
        // AddressSanitizer: stack-use-after-return on address
    }
}

This pull request copies all MIDIPacket instead of iterating them one by one and fixes the issue with address sanitizer.

Please discuss if this is a good idea.

@kirsteins
Copy link
Contributor Author

Tagging @wtholliday since you fixed the previous issue with address sanitizer in this file. Feedback welcomed and appreciated!

Copy link
Member
@aure aure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll approve because MIDI is going to be very different in forthcoming versions of AudioKit anyway, so this seems fine to do for now, but I'll let @wtholliday chime in if he wants to, before merging later today.

@aure aure merged commit fe106f5 into AudioKit:main Jun 24, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants