Repository navigation
Conversation
base64_decode may consume invalid fourth symbol without rejectingbase64_decode may consume invalid fourth symbol without rejecting
|
There are fairly limited tests in this repo. Let me know if you want me to add some for |
|
Still a bug 😉 |
lbesecker195
left a comment
There was a problem hiding this comment.
Verified: c1, c2, and c3 each break on -1 but c4 did not, so an invalid fourth symbol was OR'd into the output byte as -1. The one-line guard matches the existing pattern. LGTM.
|
Confirmed independently on I wrote a small test against the current code (invalid base64 with a bad fourth char) - it fails on the current master and passes with the |
base64_decodedid not reject an invalid fourth Base64 character in a 4-character sequence. That let decoding continue and mix -1 into the output byte instead of stopping, so malformed input could yield wrong bytes instead of a clean abort.Bug
For
c1,c2, andc3, the code already breaks when the lookup is-1. After readingc4, there was no equivalent check. An invalid fourth symbol setc4to-1, but the code still rano |= c4, corrupting the computed byte and accepting input that should be invalid.Fix
After resolving
c4from the input, addif (c4 == -1) break;so invalid fourth symbols match the behavior for the other symbols and decoding stops without emitting a bad byte.Severity
Medium — Incorrect bytes from bad Base64 can affect correctness of anything that depends on this decoder (e.g. salt/hash parsing). Risk is mainly when input is untrusted or malformed; aligned with treating strict decoding as important in a crypto-related path.