swiftlang / swiftlang/swift-corelibs-libdispatch
DispatchData.init(bytesNoCopy:deallocator:) with anything other than Deallocator.custom crashes with SEGV_ACCERR
Open
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 2.6k
- Forks
- 496
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 3
Description
On Linux, Gentoo amd64.
Reproducer:
import Foundation
let blockAllocationSize = 1024768
let p = malloc(blockAllocationSize)!
let uninitializedBuffer = DispatchData(
bytesNoCopy: .init(start: p, count: blockAllocationSize), deallocator: .free)
print(uninitializedBuffer.isEmpty)
Replacing the .free with .custom(nil, { free(p) } makes the program run correctly.
I assume this is actually a bug around @convention(block) when running without Objective-C but submitting it here first.
PID: 1898768 (test)
TID: 1898768 (test)
UID: 1000 (saiko)
GID: 100 (users)
Signal: 11 (SEGV) si_code: SEGV_ACCERR
Timestamp: Wed 2026-07-01 17:10:44 CEST (4s ago)
Command Line: ./test
Executable: /Users/saiko/test
Control Group: /user.slice/user-1000.slice/user@1000.service/app.slice/app-org.kde.konsole-1876058.scope/tab(1876070).scope
Unit: user@1000.service
User Unit: app-org.kde.konsole-1876058.scope
Slice: user-1000.slice
Owner UID: 1000 (saiko)
Boot ID: b2908daea814494bb4ced9cff518b431
Machine ID: 9cea39f4ff0243689dd77d344c5fe60c
Hostname: carcosa
Storage: /var/lib/systemd/coredump/core.test.1000.b2908daea814494bb4ced9cff518b431.1898768.1782918644000000.zst (present)
Size on Disk: 1M
Message: Process 1898768 (test) of user 1000 dumped core.
Module libunwind.so.1 without build-id.
Module libc++abi.so.1 without build-id.
Module libc++.so.1 without build-id.
Stack trace of thread 1898768:
#0 0x00007f5ae8ed5128 swift_retain (libswiftCore.so + 0x4d5128)
#1 0x00007f5ae889a3c5 $s8Dispatch0A4DataV11bytesNoCopy11deallocatorACSW_AC11DeallocatorOtcfC (libswiftDispatch.so + 0x1d3c5)
#2 0x000055e6af28c406 main (test + 0x2406)
#3 0x00007f5ae76845fe __libc_start_call_main (libc.so.6 + 0x275fe)
#4 0x00007f5ae768471b __libc_start_main_impl (libc.so.6 + 0x2771b)
#5 0x000055e6af28bf05 _start (test + 0x1f05)
ELF object binary architecture: AMD x86-64
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at DispatchData.init(bytesNoCopy:deallocator:) and reproduce the Linux crash with the provided Swift program, then inspect the libswiftDispatch stack entry shown in the report. Done means the .free deallocator path completes without SEGV_ACCERR and the reproducer prints its result normally.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, swift
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100