← all crashes · CRASH-0021 · samples/sample-c · accepted · filed 2026-09-16 14:25 UTC

CRASH-2: heap-buffer-overflow in handle_array

High8.9heap-buffer-overflowunknown
#1 handle_array @ rcfg.c:122
#2 dispatch @ rcfg.c:210
#3 rcfg_decode @ rcfg.c:247
Repro 5/5Cluster CL-5d86ee93 (5 reports: CRASH-0004, CRASH-0005, CRASH-0012, CRASH-0017)
The RCF decoder's ARRAY handler allocates a "fixed-width row table" sized by an attacker-supplied row count times row width, then fills every cell. The size used for the allocation is computed in 32-bit arithmetic and wraps, while the fill loop iterates over the true 64-bit product — so the loop writes far past the allocation. A single ARRAY field (type 0x03, 8-byte value) with rows=0x40000000 and width=4 makes the product wrap to 0, allocating a 1-byte buffer, then writes gigabytes of 0xFF. The attacker gains an out-of-bounds heap write.
Act on it
Fix
Compute the size in 64-bit and reject overflow before allocating: e.g.
Where
src/rcfg.c:handle_array:113 · reached through the unknown surface
Reproduce
run ./reproduce.sh — it clones the audited revision, builds with the sanitizer and replays the input; input input.bin (15 B); sanitizer log sanitizer.txt (3 KB); reproduced 5/5 times when re-run.
Confidence
reportable — source review placed the trigger within attacker_controls=bytes; source-anchored trigger review voted Promote on 1 verified source anchors.
Affects
boundary consumer decoding an untrusted RCF stream; attacker controls bytes; needs the caller to normal public call.

Summary

The RCF decoder's ARRAY handler allocates a "fixed-width row table" sized by an attacker-supplied row count times row width, then fills every cell. The size used for the allocation is computed in 32-bit arithmetic and wraps, while the fill loop iterates over the true 64-bit product — so the loop writes far past the allocation. A single ARRAY field (type 0x03, 8-byte value) with rows=0x40000000 and width=4 makes the product wrap to 0, allocating a 1-byte buffer, then writes gigabytes of 0xFF. The attacker gains an out-of-bounds heap write.

Fields

Field Value
Severity High8.9
Primitive heap-buffer-overflow
Location src/rcfg.c:handle_array:113
Surface unknown
Boundary consumer decoding an untrusted RCF stream
Trigger source bytes
Caller controls bytes
Caller contract unspecified
Trusted caller actions normal public call
Parameter control direct
Reproduction rate 5/5
Reproducer carrier cli
Advisory yes — no patch.diff — fix described in prose, see Fix Direction
Strategy —
Dedup frames handle_array rcfg.c:122 -> dispatch rcfg.c:210 -> rcfg_decode rcfg.c:247

Root Cause

Line 113 computes uint32_t total = rows * width; where both operands are uint32_t read from the field value (src/rcfg.c:111-112). The multiply is performed in 32-bit and silently wraps modulo 2^32. malloc(total ? total : 1) (line 115) therefore under-allocates. The fill loop on line 121 bounds itself with (size_t)rows * width — that operand is promoted to 64-bit, so it computes the true product and does not wrap. The allocation size and the loop bound are computed with different widths, breaking the invariant that the loop stays within the allocation. With rows=0x40000000, width=4, total wraps to 0 → malloc(1), but the loop runs 0x100000000 times, so table[1] is already out of bounds.

Data Flow

Attacker bytes select both dimensions of the table.

Source snippets referenced in Data Flow:

↳ Referenced in: step: rcfg_decode (src/rcfg.c:247) — dispatches the field value to the ARRAY handler.

From src/rcfg.c (lines 245–249):

245       }
246   
247 ▶     dispatch(&ctx, data, len, type, p, flen);
248   
249       p += flen;

↳ Referenced in: step: handle_array (src/rcfg.c:111-112) — reads rows and width as big-endian u32 from the value.

From src/rcfg.c (lines 109–113):

109     }
110   
111 ▶   uint32_t rows  = read_be32(val);
112     uint32_t width = read_be32(val + 4);
113     uint32_t total = rows * width;

↳ Referenced in: step: handle_array (src/rcfg.c:113) — total = rows * width overflows 32-bit and wraps.

From src/rcfg.c (lines 111–115):

111     uint32_t rows  = read_be32(val);
112     uint32_t width = read_be32(val + 4);
113 ▶   uint32_t total = rows * width;
114   
115     uint8_t *table = malloc(total ? total : 1);

↳ Referenced in: step: handle_array (src/rcfg.c:115) — malloc allocates the wrapped (tiny) size.

From src/rcfg.c (lines 113–117):

113     uint32_t total = rows * width;
114   
115 ▶   uint8_t *table = malloc(total ? total : 1);
116     if (table == NULL) {
117       return;

↳ Referenced in: step: handle_array (src/rcfg.c:121-123) — the 64-bit loop bound drives writes past the allocation.

From src/rcfg.c (lines 119–123):

119   
120     /* Fill the table cell by cell. */
121 ▶   for (size_t i = 0; i < (size_t)rows * width; i++) {
122       table[i] = 0xFF;
123     }

Impact

Any decoder of untrusted RCF streams is exposed. A 15-byte input triggers a 1-byte heap allocation followed by an out-of-bounds 0xFF write; ASan reports heap-buffer-overflow WRITE immediately at offset 1. By choosing rows/width whose 32-bit product is a chosen small non-zero value while the 64-bit product is larger, an attacker can size the allocation and control how far the write runs, giving a controllable heap-corruption primitive.

Fix Direction

Compute the size in 64-bit and reject overflow before allocating: e.g. uint64_t total = (uint64_t)rows * width; if (total > SIZE_MAX ...) return;, and use that same 64-bit value as the loop bound so allocation size and write count can never diverge. A per-field sanity cap on rows*width is also warranted.

Expected sanitizer output

==73418==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x605000000721 at pc 0x0001000a157c bp 0x00016fd5dad0 sp 0x00016fd5dac8
WRITE of size 1 at 0x605000000721 thread T0
SCARINESS: 31 (1-byte-write-heap-buffer-overflow)
==73418==WARNING: failed to spawn external symbolizer (errno: 9)
==73418==WARNING: failed to spawn external symbolizer (errno: 9)
==73418==WARNING: failed to spawn external symbolizer (errno: 9)
==73418==WARNING: failed to spawn external symbolizer (errno: 9)
==73418==WARNING: failed to spawn external symbolizer (errno: 9)
==73418==WARNING: Failed to use and restart external symbolizer!
    #0 0x0001000a1578 in handle_array rcfg.c:122
    #1 0x0001000a0d70 in dispatch rcfg.c:210
    #2 0x0001000a0a4c in rcfg_decode rcfg.c:247
    #3 0x0001000a2418 in main rcfg_cli.c:59
    #4 0x00018d1844e0 in start (in dyld) + 6988

0x605000000721 is located 0 bytes after 1-byte region [0x605000000720,0x605000000721)
allocated by thread T0 here:
    #0 0x000100839164 in wrap_malloc (in libclang_rt.asan_osx_dynamic.dylib) + 120
    #1 0x0001000a14dc in handle_array rcfg.c:115
    #2 0x0001000a0d70 in dispatch rcfg.c:210
    #3 0x0001000a0a4c in rcfg_decode rcfg.c:247
    #4 0x0001000a2418 in main rcfg_cli.c:59
    #5 0x00018d1844e0 in start (in dyld) + 6988

SUMMARY: AddressSanitizer: heap-buffer-overflow (targets/samples/sample-c/build-asan/rcfg:arm64+0x100001578) in handle_array+0x130

Full original output: sanitizer.txt.

Annotated stack frames (top-of-stack source):

#0 handle_array — rcfg.c:122

From src/rcfg.c (lines 120–124):

120     /* Fill the table cell by cell. */
121     for (size_t i = 0; i < (size_t)rows * width; i++) {
122 ▶     table[i] = 0xFF;
123     }
124   

#1 dispatch — rcfg.c:210

From src/rcfg.c (lines 208–212):

208       case RCFG_T_STR:   handle_str(ctx, val, len); break;
209       case RCFG_T_BLOB:  handle_blob(ctx, val, len); break;
210 ▶     case RCFG_T_ARRAY: handle_array(val, len); break;
211       case RCFG_T_SLICE: handle_slice(ctx, stream, stream_len, val, len); break;
212       case RCFG_T_STAGE: handle_stage(ctx, val, len); break;

#2 rcfg_decode — rcfg.c:247

From src/rcfg.c (lines 245–249):

245       }
246   
247 ▶     dispatch(&ctx, data, len, type, p, flen);
248   
249       p += flen;

#3 main — rcfg_cli.c:59

From src/rcfg_cli.c (lines 57–61):

57     }
58   
59 ▶   int fields = rcfg_decode(data, len);
60     free(data);
61   

#1 handle_array — rcfg.c:115

From src/rcfg.c (lines 113–117):

113     uint32_t total = rows * width;
114   
115 ▶   uint8_t *table = malloc(total ? total : 1);
116     if (table == NULL) {
117       return;

Reproduce

Script — reproduce.sh

Run the sibling reproduce.sh:

./reproduce.sh                 # builds/runs with ASan against the in-place audit source
./reproduce.sh /path/to/src    # or an existing checkout
Severity rationale

Severity is the CVSS v4.0 score — one industry-standard metric, computed by the vendored FIRST reference scorer. Base metrics come from the primitive and surface, with Attack Vector/Requirements also reflecting the trigger's caller-control facts (a trusted local API/call-sequence reads as AV:L/AT:P). The Threat metric (E) is read locally, not from threat intelligence: it grades how far this audit got toward proving the bug — a reproducer that fires is E:P, an unproven argument is E:U — so a demonstrated bug outranks a written one. FIRST defines E against public exploit availability, which is not what is measured here, and nothing in this run is publicly disclosed. Read E as reproduction confidence. The Environmental Security Requirements (CR/IR/AR) are left Not Defined — they model a deploying organisation's asset importance, which the scorer cannot derive, so a generic score keeps the CVSS-B worst case. Environmental modified impacts are set only to floor impact where reachability facts justify it (non-shipping surfaces, caller-only triggers). Cluster size remains a priority/verification fact because CVSS v4.0 has no cluster metric.

CVSS-BT v4.0: CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N/E:P → 8.9 (High) CVSS-B baseline: CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N → 9.3 (Critical)

Metric Value Derived from
Attack Vector (AV) N surface tier = library
Attack Complexity (AC) L fixed — not separately modelled
Attack Requirements (AT) N intrinsic attack preconditions
Privileges Required (PR) N worst case — no auth signal
User Interaction (UI) N surface tier
Vuln Conf/Integ/Avail H/H/H primitive class = heap_write
Subseq Conf/Integ/Avail N/N/N primitive class
Threat Exploit Maturity (E) P local reproduction evidence — not public exploit availability
Env Requirements (CR/IR/AR) X/X/X not defined — deployer-set asset importance (CVSS-B baseline)
Env Modified AV/AC/AT/PR/UI X/X/X/X/X caller control / contract concern
Env Modified C/I/A impacts X/X/X/X/X/X non-shipping / caller-only reachability floor; demonstrated disclosure / availability

Severity level: High — CVSS bands: Critical ≥ 9.0, High ≥ 7.0, Medium ≥ 4.0, Low ≥ 0.1, None = 0.0.

Verification facts (not part of severity — triage priority): reproduction rate 5/5; testcase + sanitizer log on disk.

Field derivation (each line is a reviewable claim):

  • surface=library → AV:N/UI:N
  • class=heap_write → VC:H/VI:H/VA:H/SC:N/SI:N/SA:N
  • class preconditions → AT:N
  • PR:N (worst case — no auth signal), AC:L
  • reproduction rate 5/5 → E:P
  • CR/IR/AR not defined — environmental requirements are a deployer concern (CVSS-B baseline)
  • caller controls input bytes → MAT:X