← all crashes · CRASH-0004 · samples/sample-c · S3 · accepted · filed 2026-09-16 14:33 UTC

CRASH-002-1: heap-buffer-overflow in handle_array

High8.2heap-buffer-overflowcli
#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-0021, CRASH-0005, CRASH-0012, CRASH-0017)
The RCF decoder's ARRAY handler allocates a row table and fills every cell. A stream carrying one ARRAY field with a row count and row width whose 32-bit product wraps to a small value reaches an allocation sized from the wrapped product while the fill loop iterates over the true 64-bit product. The external party gets an out-of-bounds heap write of caller-chosen extent. The allocation size at rcfg.c:113-115 uses rows * width in uint32_t, but the loop bound at rcfg.c:121 recomputes (size_t)rows * width in 64-bit, so the loop walks far past the buffer.
Act on it
Fix
patch.diff is captured beside this report — Compute the size in a width that cannot wrap and reject overflow before allocating: use `size_t total = (size_t)rows * width` and additionally cap against a sane maximum (the format ships "small configuration records"), or detect `width != 0 && rows > SIZE_MAX / width`..
Where
src/rcfg.c:handle_array:113 · reached through the cli surface
Reproduce
run ./reproduce.sh — it clones the audited revision, builds with the sanitizer and replays the input; input input.bin (15 B); input repro.cmd (96 B); sanitizer log sanitizer.txt (14 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 RCF stream bytes decoded by rcfg_decode (CLI file input, attacker_controls=bytes); attacker controls ARRAY field row count and row width (two big-endian u32 in the field value); needs the caller to reads a file and calls rcfg_decode(data, len) once over the exact length.

Summary

The RCF decoder's ARRAY handler allocates a row table and fills every cell. A stream carrying one ARRAY field with a row count and row width whose 32-bit product wraps to a small value reaches an allocation sized from the wrapped product while the fill loop iterates over the true 64-bit product. The external party gets an out-of-bounds heap write of caller-chosen extent. The allocation size at rcfg.c:113-115 uses rows * width in uint32_t, but the loop bound at rcfg.c:121 recomputes (size_t)rows * width in 64-bit, so the loop walks far past the buffer.

Fields

Field Value
Severity High8.2
Class memory-safety
Primitive heap-buffer-overflow
Location src/rcfg.c:handle_array:113
Surface cli— report boundary is a shipped command-line tool
Boundary RCF stream bytes decoded by rcfg_decode (CLI file input, attacker_controls=bytes)
Trigger source bytes
Caller controls ARRAY field row count and row width (two big-endian u32 in the field value)
Caller contract unspecified
Trusted caller actions reads a file and calls rcfg_decode(data, len) once over the exact length
Parameter control direct
Reproduction rate 5/5
Reproducer carrier cli
Advisory no— patch.diff included
Strategy S3— Spec vs. implementation
Dedup frames handle_array rcfg.c:122 -> dispatch rcfg.c:210 -> rcfg_decode rcfg.c:247

Root Cause

handle_array reads two caller-supplied big-endian u32 values, rows and width (rcfg.c:111-112). It computes uint32_t total = rows * width (rcfg.c:113) — a 32-bit multiply that silently wraps modulo 2^32 — and calls malloc(total ? total : 1) (rcfg.c:115). The fill loop, however, bounds itself by (size_t)rows * width (rcfg.c:121), a 64-bit multiply that does not wrap. When the 32-bit product wraps to 0 (e.g. rows = 0x40000000, width = 4, product = 2^32 ≡ 0), the table is a 1-byte allocation but the loop intends 2^32 iterations, so the very first table[1] = 0xFF is already out of bounds. The invariant the code assumes — that the allocation size equals the number of cells written — is broken because the two are computed at different widths.

Data Flow

Caller-controlled file bytes select a wrapping size product.

Source snippets referenced in Data Flow:

↳ Referenced in: step: main (src/rcfg_cli.c:59) — hands the input buffer/length to rcfg_decode.

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

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

↳ Referenced in: step: rcfg_decode (src/rcfg.c:247) — dispatches the ARRAY field (type 0x03) to handle_array.

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) — reads rows and width as big-endian u32 from the field 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 wraps in u32 to a small value.

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 small (wrapped) 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-122) — loop bounded by 64-bit rows*width writes 0xFF 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 consumer decoding an untrusted RCF stream is exposed with an ~15-byte input (magic + 3-byte header + 8-byte value). The write is 0xFF into out-of-bounds heap memory; the loop count is caller-controlled and enormous, so absent an early fault this is a large linear heap overwrite. Exploitability beyond a crash depends on heap layout, but the out-of-bounds write itself is memory-unsafe.

Fix Direction

Compute the size in a width that cannot wrap and reject overflow before allocating: use size_t total = (size_t)rows * width and additionally cap against a sane maximum (the format ships "small configuration records"), or detect width != 0 && rows > SIZE_MAX / width. Use the same 64-bit quantity for both the allocation and the loop bound so they can never diverge.

Expected sanitizer output

==76467==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x605000000721 at pc 0x0001028e957c bp 0x00016d514ab0 sp 0x00016d514aa8
WRITE of size 1 at 0x605000000721 thread T0
SCARINESS: 31 (1-byte-write-heap-buffer-overflow)
    #0 0x0001028e9578 in handle_array rcfg.c:122
    #1 0x0001028e8d70 in dispatch rcfg.c:210
    #2 0x0001028e8a4c in rcfg_decode rcfg.c:247
    #3 0x0001028ea418 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 0x000103265164 in wrap_malloc (in libclang_rt.asan_osx_dynamic.dylib) + 120
    #1 0x0001028e94dc in handle_array rcfg.c:115
    #2 0x0001028e8d70 in dispatch rcfg.c:210
    #3 0x0001028e8a4c in rcfg_decode rcfg.c:247
    #4 0x0001028ea418 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)

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

Patch

Captured patch — patch.diff (11 lines)

--- a/src/rcfg.c+++ b/src/rcfg.c@@ -110,7 +110,7 @@ static void handle_array(const uint8_t *val, uint16_t len)    uint32_t rows  = read_be32(val);   uint32_t width = read_be32(val + 4);-  uint32_t total = rows * width;+  size_t   total = (size_t)rows * width;    uint8_t *table = malloc(total ? total : 1);   if (table == NULL) {
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-BTE 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/MAT:P → 8.2 (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/P/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 limited trigger shape → MAT:P