Skip to content

Fix output length of Base64 decoded keys#55

Open
cvuosalo wants to merge 2 commits into
masterfrom
fix-decode-length3
Open

Fix output length of Base64 decoded keys#55
cvuosalo wants to merge 2 commits into
masterfrom
fix-decode-length3

Conversation

@cvuosalo

Copy link
Copy Markdown
Collaborator

The Base64Coder was added to frontier-tomcat in 2007. It was modified shortly thereafter, and a small bug was introduced. This bug added a byte to the output of the decoder when the encoded key had two padding characters. This bug had no effect until now, when more modern libraries rejected decoded keys with a trailing random byte for the case of encoded keys had two padding characters. The bug was only noticed on machines that happened to have host keys with two padding characters.

To prevent any future confusion about this code, not only has the bug been fixed, but a comment has been added to the code to help explain how the fix is correct. Also, the corrected calculation is written more explicitly and does not rely on the implicit truncation of integer arithmetic.The calculation could be written more concisely, but that would invoke the implicit truncation that caused confusion in the past and that can be difficult for the reader to easily check for correctness.

This fix was tested on cmsfrontier7 with two different sized keys. During testing, println statements were added to show the input and output lengths to confirm that the calculation was correct.

@cvuosalo cvuosalo requested a review from DrDaveD June 16, 2026 17:13
@cvuosalo cvuosalo self-assigned this Jun 16, 2026
Comment thread src/gov/fnal/frontier/codec/Base64Coder.java Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants