Closed
Description
I am writing a native addon to decode a buffer containing base64 directly into another buffer, without requiring the allocation of an interim string (see #11866 for why Node cannot decode base64 buffers directly).
I wrote a fuzz test to test my own decoder, and then decided to try it out on Node's base64 decoder.
There are a few cases where Node's decoder treats whitespace as actual data, rather than ignoring it. This happens when the "=" is left out:
// Fails:
> Buffer.from("3v6YpUFyK0/hitA2tCDIfdYKw0 g ", 'base64').toString('binary')
'Þþ�¥Ar+Oá�Ð6´ È}Ö\nÃH>'
> Buffer.from("3v6YpUFyK0/hitA2tCDIfdYKw0g ", 'base64').toString('binary')
'Þþ�¥Ar+Oá�Ð6´ È}Ö\nÃH>'
> Buffer.from("3v6YpUFyK0/hitA2tCDIfdYKw0g\n", 'base64').toString('binary')
'Þþ�¥Ar+Oá�Ð6´ È}Ö\nÃH>'
// Passes:
> Buffer.from("3v6YpUFyK0/hitA2tCDIfdYKw0g=", 'base64').toString('binary')
'Þþ�¥Ar+Oá�Ð6´ È}Ö\nÃH'
> Buffer.from("3v6YpUFyK0/hitA2tCDIfdYKw0g", 'base64').toString('binary')
'Þþ�¥Ar+Oá�Ð6´ È}Ö\nÃH'
In the failing cases, Node's decoder has interpolated a ">".