Skip to content

Soundness issue: Audio allows to borrow different inputs and outputs simultaneously #56

Description

@prokopyl

Currently, the Audio struct in clack-plugin allows to borrow multiple different inputs and outputs simultaneously, e.g. like this:

let mut ports = [None, None];

for (pair, port) in audio.port_pairs().zip(&mut ports) {
    *port = Some(pair);
}

This however can be unsound in the case where the host sends in-place (i.e. aliased) input and output buffers for different ports (which is weird but still valid according to the CLAP spec), where the current PairedChannels abstraction cannot detect it.

This was attempted to be solved in #26, but after some discussions it turns out this solution of preventing to borrow buffers as &[f32]/&mut [f32] was too restrictive for many use-cases.

Considering the only unsound case is the simultaneous borrowing of input & output, I think the solution should be some sort of in-between:

  • First, remove multiple port-pair borrowing, or only allow it in a sort of lending-style iteration.
  • Replace it with the AudioBuffer abstraction from Safe plugin buffers #26, which safely allows the common use case of copying inputs into the output buffers.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions