Permalink
Browse files

Short circuit C string parsing if past the end of the Buffer size, JS…

… version #53
  • Loading branch information...
1 parent 4811d8a commit 708e71dfb2349b60feb507553c7a92b928cf4e1b @christkv christkv committed Oct 1, 2013
Showing with 6 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +5 −1 lib/bson/bson.js
View
@@ -9,3 +9,4 @@ output
build
.bin
npm-debug.log
+builderror.log
View
@@ -1169,7 +1169,11 @@ BSON.deserialize = function(buffer, options, isArray) {
// Get the start search index
var i = index;
// Locate the end of the c string
- while(buffer[i] !== 0x00) { i++ }
+ while(buffer[i] !== 0x00 && i < buffer.length) {
+ i++
+ }
+ // If are at the end of the buffer there is a problem with the document
+ if(i >= buffer.length) throw new Error("BSON message is corrupt")
// Grab utf8 encoded string
var string = supportsBuffer && Buffer.isBuffer(buffer) ? buffer.toString('utf8', index, i) : convertUint8ArrayToUtf8String(buffer, index, i);
// Update index position

0 comments on commit 708e71d

Please sign in to comment.