# Null dereference from malformed object state

Constructors, argument unwrapping, or field init paths that leave a pointer or name null before use

_Area: Memory corruption and native code. Seen in 3 disclosed reports; 3 confirmed bounties, median $1,000, range $800-$10,000; latest 2017-03-14. Updated 2026-11-09._

## How it works
An object reaches a use site with a pointer or name field still null, and the code dereferences it without checking. The broken assumption is that every instance of a type was built through the normal path that fills its fields. When a constructor, argument-unwrapping loop, or special-case branch can complete without initializing a field, downstream code (inspect, array access, class lookup) treats the null as valid and crashes. The bug is usually in the producer, not the consumer: the consumer's contract says "field is set," and the producer silently violates it.

## Where it shows up
- Special classes exposed as normal constructors (Symbol, TrueClass, NilClass) where `new` was not undefined [E3](https://bugbountylibrary.com/r/h1%3A185957.md)
- Argument-count loops with a sentinel boundary (e.g. CALL_MAXARGS) where the wrapping branch sits inside the loop and can be skipped [E1](https://bugbountylibrary.com/r/h1%3A182484.md)
- Code that treats the first argument as an array without confirming the wrapping ran [E1](https://bugbountylibrary.com/r/h1%3A182484.md)
- VM stack/environment bookkeeping around exception unwinding, ensure, and yield [E2](https://bugbountylibrary.com/r/h1%3A212107.md)
- `inspect`/`to_s` paths calling strlen or similar on a name pointer [E3](https://bugbountylibrary.com/r/h1%3A185957.md)
- Any field read right after construction with no null guard

## How to review
For each type, list the fields consumers assume non-null. Then check every construction path, including ones reachable from user code, and confirm each field is set before any consumer runs. The invariant: no object of type T is observable with a null field that T's methods dereference. For loops, verify the special-case branch runs for every count including the exact sentinel value, not just above or below it [E1](https://bugbountylibrary.com/r/h1%3A182484.md). For special classes, confirm `new` is undefined via the same mechanism used for other singletons [E3](https://bugbountylibrary.com/r/h1%3A185957.md). For VM paths, confirm stack pointers stay within the allocated buffer across unwinding [E2](https://bugbountylibrary.com/r/h1%3A212107.md).

## How finders spotted it
- Read codegen.c gen_values while reasoning about CALL_MAXARGS; noticed the array-wrapping check only fires inside the loop and that exactly 127 args exits via t becoming null first, then traced the null deref to array.c [E1](https://bugbountylibrary.com/r/h1%3A182484.md)
- Built unusual nested module/ensure/yield control flow, then used gdb and Valgrind to trace the null RObject and out-of-bounds stack pointer [E2](https://bugbountylibrary.com/r/h1%3A212107.md)
- Noticed Symbol.new was callable unlike Ruby 2.3 (which raised NoMethodError), suspected a boxing-model issue, and confirmed the crash via inspect in mirb; compared against other singleton classes that undefine new [E3](https://bugbountylibrary.com/r/h1%3A185957.md)

## Variants seen
- Off-by-one at an argument-count sentinel leaving the first arg unwrapped [E1](https://bugbountylibrary.com/r/h1%3A182484.md)
- VM stack desync from nested ensure/yield corrupting object pointers [E2](https://bugbountylibrary.com/r/h1%3A212107.md)
- Special class constructible with no valid internal name [E3](https://bugbountylibrary.com/r/h1%3A185957.md)

## Impact and severity
All three crash the interpreter or sandbox [E1](https://bugbountylibrary.com/r/h1%3A182484.md)[E2](https://bugbountylibrary.com/r/h1%3A212107.md)[E3](https://bugbountylibrary.com/r/h1%3A185957.md). In an embedded interpreter this is a denial of service against the host; E2 additionally reads out of bounds past the stack buffer, which can leak memory or corrupt state. Severity rises when the interpreter is a sandbox boundary, since a crash or OOB read crosses it. Bounties ranged 800–10000, median 1000.

## Evidence
- E1: https://bugbountylibrary.com/r/h1%3A182484.md
- E2: https://bugbountylibrary.com/r/h1%3A212107.md
- E3: https://bugbountylibrary.com/r/h1%3A185957.md
