blog-examples icon indicating copy to clipboard operation
blog-examples copied to clipboard

Probably a bug

Open Tomas-M opened this issue 6 years ago • 1 comments

It seems to me there is a bug in the base64 decode. How could (enc3 == 64) on line 88, since you removed all paddings on line 59? enc3 can never be 64 so that check seems unnecessary.

Similarly, the line enc4 = this._keyStr.indexOf(input.charAt(j++)); seems wrong. If j>input.length, then input.charAt() = "" and indexOf("") =0, which is wrong since indexOf("A") = 0 as well. But your code works because in this case, i is already equal to bytes, so writing to uarray[i+1] writes outside of the actual array so it adds no new characters there.

https://github.com/danguer/blog-examples/blob/7614928e5f0968e078db2b0f2ac3624c96f9c7d5/js/base64-binary.js#L88

Tomas-M avatar Feb 14 '19 09:02 Tomas-M

it actually is a bug.

padding = characters must not be stripped away before processing; otherwise the resulting output may have unwanted zero bytes at the end of the array (as much as the = stripped away)

paolobertani avatar Sep 19 '22 11:09 paolobertani