-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
buffer: validate list elements in Buffer.concat #4951
Conversation
@@ -241,6 +241,8 @@ Buffer.concat = function(list, length) { | |||
var pos = 0; | |||
for (let i = 0; i < list.length; i++) { | |||
var buf = list[i]; | |||
if (!(buf instanceof Buffer)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or Buffer.isBuffer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose instanceof
for consistency (Buffer.isBuffer
is never used in this file).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was suggesting that because, if we change how we detect Buffers (which will be implemented in isBuffer
) later on, then we don't have to change this line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I changed it.
LGTM with one comment. |
LGTM with cjihrig's comment |
Marking |
I'm not sure I would classify this as |
I agree with you. Then it would be a candidate for LTS ? |
Overall, This looks to me as just an error message change. Does this qualify for backporting? @jasnell @thealphanerd |
The existing code was already checking for an array, and throwing this same error. It was a bug on our part that we didn't do adequate checking. |
LGTM |
Without this change, if any of the elements in the list to be concatenated is not a Buffer instance, the method fails with "buf.copy is not a function". Make an isBuffer check before using the copy method so that we can throw with a better message. Fixes: nodejs#4949 PR-URL: nodejs#4951 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
@nodejs/lts this commit adds a new error string |
Without this change, if any of the elements in the list to be concatenated is not a Buffer instance, the method fails with "buf.copy is not a function". Make an isBuffer check before using the copy method so that we can throw with a better message. Fixes: #4949 PR-URL: #4951 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
@rvagg in that case shouldn't it just be changed in master as well? seems strange to only change it on cherry-pick. |
@trevnorris no because master has a change that unifies all error messages, giving them consistent formatting. So what's in this is correct and nice and consistent with the rest of the codebase but that's not true of v5.x and v4.x where we need to be internally consistent with this particular file and this particular function. |
#3374 thar it is, I think there may be more work ontop of that as well |
Removed |
Should we label it as |
sure, done, but tbh I'm not sure if that's even used, @thealphanerd can you clarify how we should be using |
@rvagg we definitely use lts-watch is applied when a PR needs to be reviewed dont-land is added when we know a commit will not be backported. dont-land is particularly useful when doing audits of master to make sure we didn't miss anything |
Without this change, if any of the elements in the list to be concatenated is not a Buffer instance, the method fails with "buf.copy is not a function". Make an isBuffer check before using the copy method so that we can throw with a better message. Fixes: nodejs#4949 PR-URL: nodejs#4951 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
buffer: validate list elements in Buffer.concat
Without this change, if any of the elements in the list to be concatenated
is not a Buffer instance, the method fails with "buf.copy is not a function".
Make an instanceof check before using the copy method so that we can throw
a with a better message.
Fixes: #4949