Skip to content

isBase64 exceeds call stack for large strings #2573

@KrayzeeKev

Description

@KrayzeeKev

Describe the bug
isBase64() causes "RangeError: Maximum call stack size exceeded" on any string greater than 3355436 bytes converted to base64 (source string size quoted, base64 size is 4473916)

Examples

$ ./b64.js
ORIG: 3355437 BASE64 4473916
/PROJECT/node_modules/validator/lib/isBase64.js:28
  return (!options.padding || str.length % 4 === 0) && regex.test(str);
                                                             ^

RangeError: Maximum call stack size exceeded
    at RegExp.test (<anonymous>)
    at Object.isBase64 (/PROJECT/node_modules/validator/lib/isBase64.js:28:62)
    at Object.<anonymous> (/PROJECT/b64.js:7:23)

Reproductions
If applicable, provide a reproduction on platforms like runkit

// b64.js
const fs = require('node:fs');
const validator = require('validator');

const data = fs.readFileSync('./mb.bin');
const base64 = data.toString('base64');
console.log('ORIG:', data.length, 'BASE64', base64.length);
validator.isBase64(base64);
# Success...
$ openssl rand -out mb.bin 3355436
$ node b64.js
ORIG: 3355436 BASE64 4473916

# Failure
$ openssl rand -out mb.bin 3355437
$ node b64.js
ORIG: 3355437 BASE64 4473916
/PROJECT/node_modules/validator/lib/isBase64.js:28
  return (!options.padding || str.length % 4 === 0) && regex.test(str);
                                                             ^

RangeError: Maximum call stack size exceeded
# rest of error as per above...

Additional context
Validator.js version: 13.15.15 (13.15.0 is fine)
Node.js version: v22.15, v22.17, v24.1 (appears version independent)
OS platform: [windows, linux, macOS, etc] Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions