ruby-cext-memory-truffle-hunt
Installation
SKILL.md
Memory Safety in Ruby Native Extensions
Overview
A C extension that hands a library a raw VALUE or a raw char * and lets it outlive the
call has a dangling pointer. Two things invalidate it:
- Collection — the object is freed and its memory reused (a plain use-after-free)
- Relocation — GC compaction moves the object; the library keeps the old address
Compaction gets the attention, but collection is the more dangerous of the two: it needs no
GC.compact and fires under ordinary GC. The worst bug found with this scent library — a
google-protobuf map-key use-after-free — corrupts data silently under ordinary GC with no
compaction involved at all: one corrupted key observed across 150,000 operations, against
100/100 under GC.stress.
This is the scent library. For the hunt machinery — corpus scoping, proof protocol, delegation, filing — use truffle-hunt.