This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
Added a check for zero-length string to fix issue #2657 #2659
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The following code simply checks for zero-length strings in Buffer::Base64Write and handles them gracefully.
Without this patch, there is an intermittent failure when writing zero-length strings in Base64. On occasion, the buffer will be pulled from the buffer pool because the required length is zero and the remaining bytes in the pool is also zero. But then when the empty string is actually written to the provided buffer, it throws a TypeError because the offset is equal to the buffer length. (See code for details).
If an attempt to write a zero-length string is made and the offset is less than or equal to the buffer length, Buffer::Base64Write will now behave nicely and return a 0 as the count of characters written.
This bug was biting me during use of node-hbase which uses Buffer to decode base64 strings sent from the HBase REST server.
Hope this is helpful. I'm new to github (and git) so apologies if I've done things incorrectly.