macOS 27 beta: CFRelease(NULL) crash in HardwareDecoder::resetVideoToolBox (CVPixelBufferCreateResolvedAttributesDictionary returns NULL, released without null-check)
Which Version of libpag are you using?
libpag 4.5.50 (macOS framework, macos-arm64_x86_64 slice, UUID 3C0CD1D1-DC92-3798-A2D1-EF913562F502).
What Platform are you on?
macOS 27.0 beta (build 26A5378j), Apple Silicon (Mac16,8), arm64.
The same binary runs fine on earlier macOS releases — this only reproduces on the macOS 27 beta.
Expected Behavior
Playing a PAG that contains a video composition (hardware-decoded H.264/HEVC track) should create the VideoToolbox decoder and render normally.
Actual Behavior
The process aborts with SIGABRT. Application Specific Information:
*** CFRelease() called with NULL ***
abort() called
Root cause (symbolicated with the matching dSYM + disassembly)
The faulting thread is a libpag tgfx::TaskGroup worker. Call chain:
tgfx::TaskGroup::RunLoop
-> tgfx::Task::execute
-> tgfx::DataTask<tgfx::ImageBuffer>::onExecute (DataSource.h:103)
-> pag::SequenceReader::readBuffer (SequenceReader.cpp:29)
-> pag::VideoReader::onMakeBuffer (VideoReader.cpp:59)
-> pag::VideoReader::makeVideoDecoder (VideoReader.cpp:204)
-> pag::VideoDecoderFactory::createDecoder (VideoDecoderFactory.cpp:122)
-> pag::HardwareDecoderFactory::onCreateDecoder (HardwareDecoder.mm:31)
-> pag::HardwareDecoder::HardwareDecoder (HardwareDecoder.mm:46)
-> pag::HardwareDecoder::initVideoToolBox (HardwareDecoder.mm)
-> pag::HardwareDecoder::resetVideoToolBox (HardwareDecoder.mm:175) <-- crash
-> CoreFoundation`CFRelease + 340 (argument is NULL)
In resetVideoToolBox, the code builds a pixel-buffer attributes array and calls
CVPixelBufferCreateResolvedAttributesDictionary, then unconditionally CFReleases the
resolved dictionary output without a NULL check. Disassembly of the macOS 4.5.50 binary
(offsets shown are file offsets in the libpag image):
0x8f2c4 str xzr, [sp,#0x20] ; resolvedDict output slot pre-zeroed to NULL
0x8f2c8 add x2, sp, #0x20 ; x2 = &resolvedDict (out param)
0x8f2cc mov x0, #0x0 ; allocator = NULL
0x8f2d0 mov x1, x27 ; attributes = CFArray
0x8f2d4 bl _CVPixelBufferCreateResolvedAttributesDictionary
...
0x8f2fc bl _VTDecompressionSessionCreate
0x8f300 mov x22, x0 ; save VT status
0x8f304 ldr x0, [sp,#0x20] ; x0 = resolvedDict (STILL NULL on macOS 27)
0x8f308 bl _CFRelease ; CFRelease(NULL) -> abort <-- crash
The input attributes array libpag passes contains a single dictionary with:
kCVPixelBufferPixelFormatTypeKey = 32BGRA, kCVPixelBufferOpenGLCompatibilityKey = true,
kCVPixelBufferIOSurfacePropertiesKey = {}.
On the macOS 27 beta, CVPixelBufferCreateResolvedAttributesDictionary returns an error and
leaves resolvedDictionaryOut == NULL. Because the output is never NULL-checked before
CFRelease, the latent bug becomes a hard crash. On older macOS the call always succeeded, so
the missing check never mattered.
Suggested fix
In HardwareDecoder::resetVideoToolBox (HardwareDecoder.mm), guard the release, e.g.:
CFDictionaryRef resolved = NULL;
CVReturn r = CVPixelBufferCreateResolvedAttributesDictionary(NULL, attributes, &resolved);
// ... use `resolved` as destinationImageBufferAttributes ...
if (resolved != NULL) {
CFRelease(resolved);
}
Additionally it would be more robust to check the CVReturn and, on failure, fall back to
passing the attributes dictionary directly to VTDecompressionSessionCreate instead of relying
on the resolver.
Workaround (for anyone else hitting this)
We temporarily fix it at the app level with fishhook on macOS 27+: rebind
CVPixelBufferCreateResolvedAttributesDictionary, and when the original returns NULL, rebuild
the resolved dictionary by merging the input attributes array and returning that. This both
avoids the CFRelease(NULL) crash and lets VTDecompressionSessionCreate produce correct
BGRA/IOSurface frames — hardware decoding then renders normally.
Note: forcing software decoding via PAGVideoDecoder::SetMaxHardwareDecoderCount(0) avoids the
crash but produced corrupted output on our build, so keeping hardware decode + the resolver
fallback was the correct fix.
Code Example
Any PAG containing a hardware-decoded video composition, played on the macOS 27 beta, triggers
the crash inside HardwareDecoder::resetVideoToolBox on the first decoder creation.
PAG File
Reproduces with any PAG that has a video composition (BMP/video sequence). Happy to provide a sample privately if needed.
i have Bugfix for MacOS 27 Beta 3 and newer check this: https://github.com/Philipp1811/eufymake_Studio-MacOS-27-Beta-3-and-newer-Fix
感谢您的详细分析和反汇编排查!我们已确认这个问题,修复已提交(PR #3631),会在后续版本中包含。
Thanks. I'll use the new version going forward and remove the hook workaround on my side.