diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 7d7e355406..8d35b7e6df 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -352,7 +352,7 @@ Handle Buffer::Utf8Write(const Arguments &args) { size_t offset = args[1]->Int32Value(); - if (offset >= buffer->length_) { + if (s->Utf8Length() > 0 && offset >= buffer->length_) { return ThrowException(Exception::TypeError(String::New( "Offset is out of bounds"))); } @@ -390,7 +390,7 @@ Handle Buffer::AsciiWrite(const Arguments &args) { size_t offset = args[1]->Int32Value(); - if (offset >= buffer->length_) { + if (s->Length() > 0 && offset >= buffer->length_) { return ThrowException(Exception::TypeError(String::New( "Offset is out of bounds"))); } @@ -418,7 +418,7 @@ Handle Buffer::BinaryWrite(const Arguments &args) { size_t offset = args[1]->Int32Value(); - if (offset >= buffer->length_) { + if (s->Length() > 0 && offset >= buffer->length_) { return ThrowException(Exception::TypeError(String::New( "Offset is out of bounds"))); }