Fix CFDictionaryCreate crash: pass proper callback pointers

The crash 'CFRelease.cold.2' / '__CFStringCollectionCopy() called with NULL'
was caused by passing pointers to uninitialized CFDictionaryKeyCallBacks and
CFDictionaryValueCallBacks structs (zeroed arena allocations) to CFDictionaryCreate.
When CoreFoundation tried to call the copyDescription callback, it invoked a
NULL function pointer.

Fix: Use ffi.ptrOf(kCFTypeDictionaryKeyCallBacks) and
ffi.ptrOf(kCFTypeDictionaryValueCallBacks) to pass the standard global
callback structs instead of empty struct space.
This commit is contained in:
JohnE 2026-11-04 23:17:22 -05:00
parent 92b967bfc5
commit dc952a799c
1 changed files with 5 additions and 9 deletions

View File

@ -1,4 +1,4 @@
import 'dart:ffi';
import 'dart:ffi' as ffi;
import 'dart:typed_data';
import 'package:ffi/ffi.dart';
@ -220,15 +220,13 @@ final class ImageConverterDarwin implements ImageConverterPlatform {
.retainAndAutorelease()
.cast<Void>();
final keyCallBacks = arena<CFDictionaryKeyCallBacks>();
final valueCallBacks = arena<CFDictionaryValueCallBacks>();
return CFDictionaryCreate(
kCFAllocatorDefault,
keys.cast(),
values.cast(),
1,
keyCallBacks,
valueCallBacks,
ffi.ptrOf(kCFTypeDictionaryKeyCallBacks),
ffi.ptrOf(kCFTypeDictionaryValueCallBacks),
);
});
}
@ -362,15 +360,13 @@ final class ImageConverterDarwin implements ImageConverterPlatform {
keys[2] = kCGImageSourceThumbnailMaxPixelSize.cast();
values[2] = maxPixelSize.toNSNumber().ref.retainAndAutorelease().cast();
final keyCallbacks = arena<CFDictionaryKeyCallBacks>();
final valueCallbacks = arena<CFDictionaryValueCallBacks>();
final opts = CFDictionaryCreate(
kCFAllocatorDefault,
keys.cast(),
values.cast(),
3,
keyCallbacks,
valueCallbacks,
ffi.ptrOf(kCFTypeDictionaryKeyCallBacks),
ffi.ptrOf(kCFTypeDictionaryValueCallBacks),
);
if (opts == nullptr) return null;