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: buffer-alloc pads a buffer by repeating #8

Merged
merged 1 commit into from
Feb 28, 2018

Conversation

aviadatsnyk
Copy link
Contributor

There seems to be a bug in the code. Since buffer-alloc is not padding with zeros, but rather duplicates the string it was given. For example the string "a" will be deemed equal to the string "aaaaaa".

> require('safe-compare')('a', 'aaaaaaaaaaaa')
true

This pr mitigates this by right-padding the buffer with zeros.

@aviadatsnyk aviadatsnyk changed the title fix: buffer-alloc pads a buffer by repeating (#1) fix: buffer-alloc pads a buffer by repeating Feb 21, 2018
@coveralls
Copy link

coveralls commented Feb 21, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 9f51dd9 on aviadatsnyk:master into b29bad3 on Bruce17:master.

@coveralls
Copy link

coveralls commented Feb 21, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 3c62de2 on aviadatsnyk:master into b29bad3 on Bruce17:master.

1 similar comment
@coveralls
Copy link

coveralls commented Feb 21, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 3c62de2 on aviadatsnyk:master into b29bad3 on Bruce17:master.

@Bruce17
Copy link
Owner

Bruce17 commented Feb 21, 2018

This is interesting: I cannot reproduce your error.

Which package and Node.js version are you using?

@aviadatsnyk
Copy link
Contributor Author

safe-compare@1.1.1
node@6.11.5 and node@8.9.3

@Bruce17
Copy link
Owner

Bruce17 commented Feb 22, 2018

@aviadatsnyk now I can reproduce it (actually I had a problem with nvm, my fault).

Please change your code to:

var bufA = bufferAlloc(len, 0, 'utf8');
bufA.write(strA);
var bufB = bufferAlloc(len, 0, 'utf8');
bufB.write(strB);

* fix: buffer-alloc pads a buffer by repeating

* add a test
@aviadatsnyk
Copy link
Contributor Author

@Bruce17 done.

@Bruce17 Bruce17 merged commit 38bc6f3 into Bruce17:master Feb 28, 2018
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