Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Invalid base64 length when encode base64 #933

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

wklaczynski
Copy link

@wklaczynski wklaczynski commented Dec 27, 2021

When using the base64 encoding function, it is often the case that the digitized string is too short to be divisible by 4. This is because some numbers using charCodeAt are too large and fall outside the range of 64 by substituting none in place of the code. The situation is improved by adding alignment to byte.

util.binary.base64.encode = function(input, maxline) {
  var line = '';
  var output = '';
  var chr1, chr2, chr3;
  var i = 0;
  while(i < input.byteLength) {
    chr1 = input[i++] & 0xff;
    chr2 = input[i++] & 0xff;
    chr3 = input[i++] & 0xff;
util.encode64 = function(input, maxline) {
  // TODO: deprecate: "Deprecated. Use util.binary.base64.encode instead."
  var line = '';
  var output = '';
  var chr1, chr2, chr3;
  var i = 0;
  while(i < input.length) {
    chr1 = input.charCodeAt(i++) & 0xff;
    chr2 = input.charCodeAt(i++) & 0xff;
    chr3 = input.charCodeAt(i++) & 0xff;

@davidlehn
Copy link
Member

Can you please add a test case to the test suite that shows the error and that the fix works. Thanks.

@davidlehn
Copy link
Member

Also see #932.

@davidlehn
Copy link
Member

That last commit title is confusing, did you commit the right files? We're not currently using package-lock.json in this project. Please remove it from the PR history.

@davidlehn davidlehn added the bug label Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants