string->number⁠ hangs and OOMs on tiny payloads like ⁠"#e1e99999999"⁠ (unbounded allocation)

Open
#1,059 5 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Domain
backend

Research direction

Start by locating the implementation and tests for string->number, then trace how exact exponents are parsed and allocated. Reproduce with (string->number "#e1e99999999") under a timeout and inspect the related discussion for constraints. Done means untrusted input is refused within bounded time and memory, with regression coverage for the reproduction.

Written by the indexing model from the issue text.

Description

Calling ⁠(string->number "#e1e99999999")⁠ attempts to construct the exact integer 10^99999999.

Because the allocation is unbounded, this call never returns. It just spins and eats RAM—I watched a Scheme process balloon to 20 GB before it was finally killed.

This is a significant DoS risk. Any program that feeds untrusted user input into ⁠string->number⁠ can be locked up and OOM'd by a 12-character string.

The obvious mitigations don't actually work:

Forcing a radix: ⁠(string->number "#e1e99999999" 10)⁠ still hangs because the radix argument doesn't disable ⁠#e⁠ / ⁠#x⁠ prefixes.

Length limits: Bounding the input length doesn't help because the malicious part is just the exponent, which easily fits in a dozen characters.

To reproduce:
、、、
$ timeout 5 scheme -q <<< '(string->number "#e1e99999999")'
$ echo $?
124
、、、

Expected behavior:

There needs to be a bounded refusal (e.g., returning ⁠#f⁠ or throwing an exception when an exact exponent exceeds a reasonable limit). Alternatively, we need a documented, safe way to parse numbers from untrusted text. Right now, the only safe workaround is to manually validate the string's shape before passing it to ⁠string->number.

Dominant language
Scheme
Stars
7.4k
Forks
1k
Avg merge
1d 20h
Merged PRs (30d)
19

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cisco/ChezScheme

All issues in cisco/ChezScheme

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.