CRASH-3: heap-buffer-overflow in handle_slice
handle_slice @ rcfg.c:147dispatch @ rcfg.c:211rcfg_decode @ rcfg.c:247[offset, offset+length) window out of the whole input stream into a scratch buffer and checksums it. It validates only the start offset against the stream length, never offset + length, so a window that starts near the end of the stream reads past the end of the input buffer. A single SLICE field (type 0x04, 4-byte value) with off equal to the stream length and want=512 reads 512 bytes beyond the heap allocation. The attacker gains an out-of-bounds heap read of adjacent memory../reproduce.sh — it clones the audited revision, builds with the sanitizer and replays the input; input input.bin (11 B); sanitizer log sanitizer.txt (3 KB); reproduced 5/5 times when re-run.Summary¶
The RCF decoder's SLICE handler copies a [offset, offset+length) window out of the whole input stream into a scratch buffer and checksums it. It validates only the start offset against the stream length, never offset + length, so a window that starts near the end of the stream reads past the end of the input buffer. A single SLICE field (type 0x04, 4-byte value) with off equal to the stream length and want=512 reads 512 bytes beyond the heap allocation. The attacker gains an out-of-bounds heap read of adjacent memory.
Fields¶
| Field | Value |
|---|---|
| Severity | Medium5.5 |
| Primitive | heap-buffer-overflow |
| Location | src/rcfg.c:handle_slice:147 |
| 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_slice rcfg.c:147 -> dispatch rcfg.c:211 -> rcfg_decode rcfg.c:247 |
Root Cause¶
Line 141 guards with if (off > stream_len) return; — this permits off == stream_len and any off up to the end. The copy length is then n = min(want, 512) (line 146) and line 147 does memcpy(window, stream + off, n). The invariant a safe copy needs is off + n <= stream_len; the code only checks off <= stream_len. When off sits at or near stream_len, stream + off points at or past the last valid byte and the memcpy reads up to 512 bytes out of bounds. off and want are big-endian u16 values taken directly from the field value (src/rcfg.c:138-139), and the stream buffer is a heap allocation sized to the exact file length (src/rcfg_cli.c:29), so ASan flags the read precisely.
Data Flow¶
Attacker bytes choose the window start and length; the base is the whole input.
- step: rcfg_decode (src/rcfg.c:247) — passes the full stream base and length to the SLICE handler.
- step: handle_slice (src/rcfg.c:138-139) — reads
offandwantas big-endian u16 from the value. - step: handle_slice (src/rcfg.c:141) — validates only
off > stream_len, ignoringoff + n. - step: handle_slice (src/rcfg.c:146) — clamps the copy length to 512 but not to remaining stream.
- step: handle_slice (src/rcfg.c:147) —
memcpyreadsnbytes fromstream + off, past the buffer end.
Source snippets referenced in Data Flow:
↳ Referenced in: step: rcfg_decode (src/rcfg.c:247) — passes the full stream base and length to the SLICE 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_slice (src/rcfg.c:138-139) — reads off and want as big-endian u16 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) — validates only off > stream_len, ignoring off + n.
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:146) — clamps the copy length to 512 but not to remaining stream.
From src/rcfg.c (lines 144–148):
144
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);
↳ Referenced in: step: handle_slice (src/rcfg.c:147) — memcpy reads n bytes from stream + off, past the buffer end.
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 decoder of untrusted RCF streams is exposed. An 11-byte input reads 512 bytes past an 11-byte heap allocation (ASan heap-buffer-overflow READ). The out-of-bounds bytes are folded into ctx->slice_sum but not directly returned, so this is primarily a crash / adjacent-heap disclosure primitive; direct exfiltration of the read bytes beyond the crash is unproven. It can still leak via timing/observable side effects and is a reliable remote crash.
Fix Direction¶
Validate the full window: after computing n, require off <= stream_len && n <= stream_len - off (compute the remaining span as stream_len - off and clamp n to it) before the memcpy. Checking only the start offset is insufficient because the length is independently attacker-chosen.
Expected sanitizer output¶
==73422==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6050000006db at pc 0x0001016eec84 bp 0x00016f0f17d0 sp 0x00016f0f0f80
READ of size 512 at 0x6050000006db thread T0
SCARINESS: 26 (multi-byte-read-heap-buffer-overflow)
==73422==WARNING: failed to spawn external symbolizer (errno: 9)
==73422==WARNING: failed to spawn external symbolizer (errno: 9)
==73422==WARNING: failed to spawn external symbolizer (errno: 9)
==73422==WARNING: failed to spawn external symbolizer (errno: 9)
==73422==WARNING: failed to spawn external symbolizer (errno: 9)
==73422==WARNING: Failed to use and restart external symbolizer!
#0 0x0001016eec80 in __asan_memcpy (in libclang_rt.asan_osx_dynamic.dylib) + 1024
#1 0x000100d0d790 in handle_slice rcfg.c:147
#2 0x000100d0cd8c in dispatch rcfg.c:211
#3 0x000100d0ca4c in rcfg_decode rcfg.c:247
#4 0x000100d0e418 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 0x0001016f1164 in wrap_malloc (in libclang_rt.asan_osx_dynamic.dylib) + 120
#1 0x000100d0e610 in read_file rcfg_cli.c:29
#2 0x000100d0e3a8 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) in handle_slice+0x1d4
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-BT 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 → 5.5 (Medium) 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/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: Medium — 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 input bytes → MAT:X