← all crashes · CRASH-0011 · samples/sample-c · S7 · accepted · filed 2026-09-16 14:34 UTC

CRASH-004-2: heap-buffer-overflow in handle_slice

Low2.9heap-buffer-overflowcli
#1 handle_slice @ rcfg.c:147
#2 dispatch @ rcfg.c:211
#3 rcfg_decode @ rcfg.c:247
Repro 5/5Cluster CL-80016dd9 (5 reports: CRASH-0022, CRASH-0007, CRASH-0009, CRASH-0018)
The RCF decoder's SLICE field copies a [offset, offset+length) window out of the whole input stream into a scratch buffer and checksums it. The offset is validated with off > stream_len, which permits off == stream_len, and the length is never checked against the bytes actually available from that offset, so the copy reads past the end of the stream buffer. The shortest input is the 4-byte magic RCF1, a 3-byte field header 04 00 04, then four value bytes 00 0B 00 64 (offset 11 == the 11-byte stream length, want 100). The caller who supplies the stream bytes gets a heap over-read of up to 512 bytes past the input allocation.
Act on it
Fix
Validate the full window against the stream, not just the offset: after computing `n`, require `off <= stream_len && n <= stream_len - off` (using the non-strict offset bound only together with the length check), and reject or clamp otherwise.
Where
src/rcfg.c:handle_slice:141 · reached through the cli surface
Reproduce
run ./reproduce.sh — it clones the audited revision, builds with the sanitizer and replays the input; input input.rcf (11 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 read from the input file (rcfg_decode public API / CLI); attacker controls full stream contents — field type tag, u16 length, and the u16 offset/want in the SLICE value; needs the caller to calls rcfg_decode(data, len) once over the exact file length; no internal state mutated.

Summary

The RCF decoder's SLICE field copies a [offset, offset+length) window out of the whole input stream into a scratch buffer and checksums it. The offset is validated with off > stream_len, which permits off == stream_len, and the length is never checked against the bytes actually available from that offset, so the copy reads past the end of the stream buffer. The shortest input is the 4-byte magic RCF1, a 3-byte field header 04 00 04, then four value bytes 00 0B 00 64 (offset 11 == the 11-byte stream length, want 100). The caller who supplies the stream bytes gets a heap over-read of up to 512 bytes past the input allocation.

Fields

Field Value
Severity Low2.9
Class memory-safety
Primitive heap-buffer-overflow
Location src/rcfg.c:handle_slice:141
Surface cli— report boundary is a shipped command-line tool
Boundary RCF stream bytes read from the input file (rcfg_decode public API / CLI)
Trigger source bytes
Caller controls full stream contents — field type tag, u16 length, and the u16 offset/want in the SLICE value
Caller contract unspecified
Trusted caller actions calls rcfg_decode(data, len) once over the exact file length; no internal state mutated
Parameter control direct
Reproduction rate 5/5
Reproducer carrier cli
Advisory yes — no patch.diff — fix described in prose, see Fix Direction
Strategy S7— Adversarial input
Dedup frames handle_slice rcfg.c:147 -> dispatch rcfg.c:211 -> rcfg_decode rcfg.c:247

Root Cause

handle_slice reads off = read_be16(val) and want = read_be16(val + 2) (src/rcfg.c:138-139). It guards only the offset, and with a non-strict comparison: if (off > stream_len) return; (src/rcfg.c:141). This lets off == stream_len through — a position one past the last valid byte. It then copies n = want < sizeof(window) ? want : sizeof(window) bytes with memcpy(window, stream + off, n) (src/rcfg.c:145-147). The wrong assumption is that a valid offset guarantees n readable bytes from that offset; the code never checks off + n <= stream_len. stream and stream_len are the whole input buffer and its length (passed from rcfg_decode, src/rcfg.c:247, which receives them from read_file in the CLI). With off = stream_len and any want > 0, memcpy reads min(want, 512) bytes starting one byte past the allocation, over-reading the heap buffer allocated in read_file (src/rcfg_cli.c:29).

Data Flow

A SLICE field with offset equal to the stream length and a non-zero want reads past the end of the input buffer.

Source snippets referenced in Data Flow:

↳ Referenced in: step: read_file (src/rcfg_cli.c:29) — allocates an 11-byte buffer for the whole input file.

From src/rcfg_cli.c (lines 27–31):

27     }
28   
29 ▶   uint8_t *buf = malloc((size_t)size);
30     if (buf == NULL) {
31       fclose(fp);

↳ Referenced in: step: main (src/rcfg_cli.c:59) — calls rcfg_decode(data=stream, len=11).

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 type-0x04 field, passing the whole stream and its length to handle_slice.

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_slice (src/rcfg.c:138) — reads off=11, want=100 from the value.

From src/rcfg.c (lines 136–140):

136     }
137   
138 ▶   uint16_t off  = read_be16(val);
139     uint16_t want = read_be16(val + 2);
140   

↳ Referenced in: step: handle_slice (src/rcfg.c:141) — guard off > stream_len (11 > 11) is false, so the field is accepted.

From src/rcfg.c (lines 139–143):

139     uint16_t want = read_be16(val + 2);
140   
141 ▶   if (off > stream_len) {
142       return;
143     }

↳ Referenced in: step: handle_slice (src/rcfg.c:147) — memcpy(window, stream+11, 100) reads 100 bytes starting 0 bytes past the 11-byte allocation; ASan…

From src/rcfg.c (lines 145–149):

145     uint8_t window[RCFG_SLICE_CAP];
146     size_t  n = want < sizeof(window) ? want : sizeof(window);
147 ▶   memcpy(window, stream + off, n);
148     ctx->slice_sum = checksum(window, n);
149   }

Impact

Any producer of an RCF stream can force the decoder to read up to 512 bytes past the end of the input buffer, reachable through the sole documented input boundary (a file of stream bytes). The over-read bytes are folded into a checksum (ctx->slice_sum) that is not returned to the caller, so this is primarily a crash / out-of-bounds read of adjacent heap; direct information disclosure is unproven.

Fix Direction

Validate the full window against the stream, not just the offset: after computing n, require off <= stream_len && n <= stream_len - off (using the non-strict offset bound only together with the length check), and reject or clamp otherwise. Guarding the offset alone leaves the length unbounded past the end.

Expected sanitizer output

==77321==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6050000006db at pc 0x000102a02c84 bp 0x00016db90790 sp 0x00016db8ff40
READ of size 100 at 0x6050000006db thread T0
SCARINESS: 26 (multi-byte-read-heap-buffer-overflow)
    #0 0x000102a02c80 in __asan_memcpy (in libclang_rt.asan_osx_dynamic.dylib) + 1024
    #1 0x00010226d790 in handle_slice rcfg.c:147
    #2 0x00010226cd8c in dispatch rcfg.c:211
    #3 0x00010226ca4c in rcfg_decode rcfg.c:247
    #4 0x00010226e418 in main rcfg_cli.c:59
    #5 0x00018d1844e0 in start (in dyld) + 6988

0x6050000006db is located 0 bytes after 11-byte region [0x6050000006d0,0x6050000006db)
allocated by thread T0 here:
    #0 0x000102a05164 in wrap_malloc (in libclang_rt.asan_osx_dynamic.dylib) + 120
    #1 0x00010226e610 in read_file rcfg_cli.c:29
    #2 0x00010226e3a8 in main rcfg_cli.c:53
    #3 0x00018d1844e0 in start (in dyld) + 6988

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

Full original output: sanitizer.txt.

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

#1 handle_slice — rcfg.c:147

From src/rcfg.c (lines 145–149):

145     uint8_t window[RCFG_SLICE_CAP];
146     size_t  n = want < sizeof(window) ? want : sizeof(window);
147 ▶   memcpy(window, stream + off, n);
148     ctx->slice_sum = checksum(window, n);
149   }

#2 dispatch — rcfg.c:211

From src/rcfg.c (lines 209–213):

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;
213       case RCFG_T_DROP:  handle_drop(ctx); break;

#3 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;

#4 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 read_file — rcfg_cli.c:29

From src/rcfg_cli.c (lines 27–31):

27     }
28   
29 ▶   uint8_t *buf = malloc((size_t)size);
30     if (buf == NULL) {
31       fclose(fp);

#2 main — rcfg_cli.c:53

From src/rcfg_cli.c (lines 51–55):

51   
52     size_t   len = 0;
53 ▶   uint8_t *data = read_file(argv[1], &len);
54     if (data == NULL) {
55       fprintf(stderr, "could not read input\n");

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-BTE v4.0: CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N/E:P/MAT:P → 2.9 (Low) CVSS-B baseline: CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N → 6.9 (Medium)

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 N/N/L primitive class = heap_read_big
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: Low — 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_read_big → VC:N/VI:N/VA:L/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