Skip to content

Ciphey — unbounded Brainfuck interpreter hangs the whole program on crafted input (DoS)

Moderate
bee-san published GHSA-5frc-8c8j-rcvf Aug 31, 2026

Package

cargo ciphey (Rust)

Affected versions

= 0.12.0

Patched versions

0.12.1

Description

Summary

Ciphey's Brainfuck decoder runs a Turing-complete interpreter on untrusted input with no execution bound:

// src/decoders/brainfuck_interpreter.rs:65
match Brainfuck::new(text).with_output_ref(&mut buf).execute() {

brainfuck-exe 0.2.4 exposes with_instructions_limit(usize) whose default is None = no limit (crate lib.rs:189), and Ciphey never sets it. The decoder's only guards (lines 53–62) are trivial to satisfy:

  • text.contains(',') → reject (no stdin reads)
  • !text.ends_with('.') || text.matches('.').count() < 5 → need ≥5 . and end with .
  • text.matches(|c| "+-<>[]".contains(c)).count() < 20 → need ≥20 command chars

A single crafted input passes all three and runs forever, producing unbounded output. Because the Brainfuck decoder is a registered, active decoder (src/decoders/mod.rs:252) that the A* searcher runs on every input node, feeding Ciphey such input — directly, or any input its search decodes into it at some layer — hangs the whole program at 100% CPU with unbounded memory growth. There is no per-input decoder gating that would spare it: filtration_system::filter_and_get_decoders(_text_struct) ignores the input entirely (its argument is unused), and Decoders::run calls .crack() on every component (src/filtration_system/mod.rs:61), so the Brainfuck decoder's own guards are the only thing standing between untrusted input and execute(). Ciphey's entire purpose is processing untrusted input (CTF, forensics, automated pipelines), so this is squarely in its threat model.

Proof of concept (input)

++++++++++++++++++++[.....].
  • Passes the guards: 6 ., 22 command chars (20×'+' + [ + ]), ends with ., no ,.
  • Cell 0 = 20 and is never decremented inside [.....], so the loop condition (cell 0 ≠ 0) never becomes false → infinite loop; the trailing . is never reached.

Verified on the exact crate Ciphey ships (brainfuck-exe = 0.2.4, default-features = false):

[control-hello]  ">++++++++[<+++++++++>-]<. ...<+."   -> TERMINATED in 42µs, output "Hello, World!"
[BOMB]           "++++++++++++++++++++[.....]."       -> SIGKILL'd at an 8s wall-clock timeout (never terminates)

The control proves the harness runs Brainfuck correctly, so the bomb's non-termination is attributable to the input, not a broken harness. Left running, the output Vec grows without limit (observed ~71 MB accumulated in ~13 s even under a loose 100M-instruction cap) → OOM in addition to the hang.

Why the global timeout does NOT mitigate it

Ciphey has a global config.timeout (src/searchers/mod.rs:46). It does not rescue this case. The search runs in a spawned thread; on timeout the main thread sets a stop flag and then calls:

// src/searchers/mod.rs:88
handle.join().unwrap();

A decoder stuck inside brainfuck-exe's execute() never returns to the search loop to observe stop, so handle.join() blocks forever — the program hangs permanently even after the timer "expires." A cooperative-cancellation flag cannot interrupt a non-cooperative infinite loop in a third-party interpreter.

Fix (one line; uses the crate's own API, existing error handling already catches it)

Set an instruction limit on the interpreter. When the cap trips, brainfuck-exe returns Err(BrainfuckError::… instructions reached the set limit) (crate error.rs:29), which the decoder's existing Err(e) => { … results } arm (line 74) already handles as "not Brainfuck" — no other change needed:

match Brainfuck::new(text)
        .with_instructions_limit(BF_INSTRUCTION_CAP)   // <-- the fix
        .with_output_ref(&mut buf)
        .execute()
{

Verified: with .with_instructions_limit(...) the PoC returns Err instead of hanging, and the decoder yields no result. Choose BF_INSTRUCTION_CAP tight enough that DoS is bounded to sub-second while real Brainfuck decodes still succeed — a legitimate decode is small (Hello-World ≈ hundreds of instructions); something on the order of low-millions is generous. Consider also with_mem_size(...) to bound the tape and capping the decoded-output length (a huge but finite output would still feed a giant string into the A* search). A private fix PR accompanies this report.

Scope / honest caveats

This is a denial-of-service finding only — no code execution, no data exposure. Impact is a permanent hang (and unbounded memory) of the Ciphey process on a crafted input; severity turns on A:H (a non-recoverable infinite loop, standard for a decode-bomb/ReDoS-class DoS). A maintainer who treats a killable CLI hang as A:L would score it ~3.3; the non-preemptible handle.join() and the unbounded allocation are why we score A:H. Verified against master @ bc65a71. Rust's regex-crate-based checkers are linear-time and were not found ReDoS-prone; this report is specifically the Brainfuck interpreter.

Reporter transparency

Found in review and verified with our own execution-based tooling, with AI assistance (Anthropic Claude/Opus). Every quantitative claim comes from running your own crate/code — please re-run the PoC. Happy to help land the fix or coordinate on timing.

Severity

Moderate

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Local
Attack complexity
Low
Privileges required
None
User interaction
Required
Scope
Unchanged
Confidentiality
None
Integrity
None
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H

CVE ID

No known CVE

Weaknesses

Uncontrolled Resource Consumption

The product does not properly control the allocation and maintenance of a limited resource. Learn more on MITRE.

Loop with Unreachable Exit Condition

The product contains an iteration or loop with an exit condition that cannot be reached, i.e., an infinite loop. Learn more on MITRE.

Credits