Skip to content

Schema.isBase64 / isBase64Url throw RangeError on multi-megabyte strings #9592

Closed

Description

@magoz

What version of Effect is running?

4.0.5 (also current main, bbedfc7)

What steps can reproduce the bug?

import { Schema } from "effect"

const input = "A".repeat(4_000_000) // valid Base64 / Base64Url, ~3 MB decoded

Schema.decodeUnknownSync(Schema.String.check(Schema.isBase64()))(input)
Schema.decodeUnknownSync(Schema.String.check(Schema.isBase64Url()))(input)

What is the expected behavior?

Both decode successfully (or fail with a schema issue for invalid input).

What do you see instead?

  • 4.0.5: RangeError: Maximum call stack size exceeded
  • main: Error: Sync adapter can only throw schema errors, cause Cause([Die(RangeError: Maximum call stack size exceeded)]). Schema.is and decodeUnknownResult throw too.

Additional information

The bare regex throws as well, so the problem is the pattern, not Schema:

/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/.test("A".repeat(4_000_000))
// RangeError: Maximum call stack size exceeded

V8's regexp engine keeps backtracking state for each iteration of the repeated (...{4})* group. On Node v24.21.0 (V8 13.6), both patterns accept 3,728,260 chars and throw from 3,728,264 chars (932,066 groups, ~2.67 MiB decoded). Base64 strings produced by Buffer#toString("base64") fail at the same length. The limit stays the same with --stack-size=400 and --stack-size=4000. Non-capturing (?:...) groups also throw at 8M chars. A flat ^[0-9a-zA-Z+/]*$ does not, and neither do Base64.decode / Base64Url.decode from effect/encoding (~20 ms at 8M chars).

In practice, Base64 payloads such as file attachments above ~2.7 MB cannot be validated. I checked the other regex-backed string checks (isTrimmed, isUUID, isGUID, isULID, isStringFinite, isStringBigInt, isStringSymbol, isUppercased, isCapitalized, isStartingWith) on 8M-char inputs, and none of them throw.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions