validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

isBase64 exceeds call stack for large strings

Open KrayzeeKev opened this issue 6 months ago • 5 comments

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

KrayzeeKev avatar Jul 11 '25 01:07 KrayzeeKev

Thanks for opening this bug report. It has also been mentioned here; https://github.com/validatorjs/validator.js/pull/2491 but without a reproducible example.

I'm open to reviewing any PRs from the community to fix this

WikiRik avatar Jul 11 '25 09:07 WikiRik

Created #2574

KrayzeeKev avatar Jul 14 '25 05:07 KrayzeeKev

@WikiRik thanks , i provided an example, which reproduces the issue. I would appreciate it if the problem could be resolved

andreasvh-conceto avatar Jul 25 '25 13:07 andreasvh-conceto

this issue can be successfully closed with the merge of https://github.com/validatorjs/validator.js/pull/2574 right? :)

andreasvh-conceto avatar Aug 30 '25 15:08 andreasvh-conceto

this issue can be successfully closed with the merge of #2574 right? :)

Once #2585 has been merged and released I would say so

WikiRik avatar Aug 30 '25 20:08 WikiRik