commit ce90339d90026caf72cdf791283ad97687f574e7
parent 91ddb316f6d25fff5af17efb71809a147905397d
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Fri, 18 Sep 2026 13:15:45 -0400
audio: [macOS] do not read the packet description out-parameter
The converter's input callback passed packet descriptions along to the
file reader by reading them back out of its own out-parameter. That only
works for variable bitrate input, where the callback has just written
them. Constant bitrate input has no packet descriptions, so the
parameter arrives uninitialised and the reader was handed whatever
happened to be on the stack.
Nothing caught it because the only fixture was AAC, which is variable
bitrate. The first constant bitrate input to reach this code, a plain
WAV from the format tests, wedged the converter until the test timeout.
The callback now keeps its own pointer, nil unless it has descriptions
to give, and writes it out rather than reading it back.
Diffstat:
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/audio_macos.go b/audio_macos.go
@@ -507,17 +507,31 @@ func InputDataProc(
) C.OSStatus {
ic := cgo.Handle(uintptr(inUserData)).Value().(*InputContext)
+ // Only variable bitrate input carries packet descriptions. Constant
+ // bitrate input has none, and there the out-parameter arrives
+ // uninitialised, so reading it back to pass along, as this used to,
+ // hands the file reader whatever happened to be on the stack.
+ //
+ // Nothing caught it because the only fixture was AAC, which is
+ // variable. The first constant bitrate input, a plain WAV, wedged the
+ // converter until the test timeout.
+ var packetDescriptions *C.AudioStreamPacketDescription
+
if ic.mInputUsesPacketDescriptions == _true {
// Cap the number of data packets to the capacity of the slice.
if int(*ioNumberDataPackets) > cap(ic.mPacketDescriptions) {
*ioNumberDataPackets = C.UInt32(cap(ic.mPacketDescriptions))
}
- *outDataPacketDescription = unsafe.SliceData(ic.mPacketDescriptions)
+ packetDescriptions = unsafe.SliceData(ic.mPacketDescriptions)
+ }
+
+ if outDataPacketDescription != nil {
+ *outDataPacketDescription = packetDescriptions
}
if err := ic.mInputFile.ReadPackets(
&ioData.mBuffers[0].mDataByteSize,
- *outDataPacketDescription,
+ packetDescriptions,
ioNumberDataPackets,
ioData.mBuffers[0].mData,
); err != nil {