Skip to content

Commit 1f9cdc9

Browse files
committed
Add another sanity check for Buffer#write
1 parent 7291685 commit 1f9cdc9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,10 @@ function ucs2Write (buf, string, offset, length) {
897897
}
898898

899899
Buffer.prototype.write = function write (string, offset, length, encoding) {
900+
if (typeof string !== 'string') {
901+
throw new TypeError('"string" argument must be a string')
902+
}
903+
900904
// Buffer#write(string)
901905
if (offset === undefined) {
902906
encoding = 'utf8'
@@ -926,7 +930,7 @@ Buffer.prototype.write = function write (string, offset, length, encoding) {
926930
const remaining = this.length - offset
927931
if (length === undefined || length > remaining) length = remaining
928932

929-
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
933+
if (length < 0 || offset < 0 || offset > this.length) {
930934
throw new RangeError('Attempt to write outside buffer bounds')
931935
}
932936

0 commit comments

Comments
 (0)