Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

rvermillion
Copy link

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.

@rvermillion
Copy link
Author

Oh, one thing. I made the commit on a new branch created from the v0.6.9 tag. I'm not sure if this is the correct way to provide patches to specific versions, so hopefully it's not wrong -- as I said, I'm new to this git business.

@bnoordhuis
Copy link
Member

Sorry, I ended up not taking your patch. It turned out that there was another bug in the base64 decoder that I fixed in f101f7c but afterwards your patch no longer applied. Despair not, the issue is fixed in 7e40c7d and will be included in tonight's release. Thanks for the report!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants