Socket
Socket
Sign inDemoInstall

redis-parser

Package Overview
Dependencies
0
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.4 to 2.1.0

8

changelog.md

@@ -0,1 +1,9 @@

## v.2.1.0 - 30 Oct, 2016
Features
- Improve parser errors by adding more detailed information to them
- Accept manipulated Object.prototypes
- Unref the interval if used
## v.2.0.4 - 21 Jul, 2016

@@ -2,0 +10,0 @@

51

lib/parser.js

@@ -66,2 +66,5 @@ 'use strict'

* end ranges. Checks `optionReturnBuffers`.
*
* If returnBuffers is active, all return values are returned as buffers besides numbers and errors
*
* @param parser

@@ -73,3 +76,2 @@ * @param start

function convertBufferRange (parser, start, end) {
// If returnBuffers is active, all return values are returned as buffers besides numbers and errors
parser.offset = end + 2

@@ -116,2 +118,7 @@ if (parser.optionReturnBuffers === true) {

* Parse a ':' redis integer response
*
* If stringNumbers is activated the parser always returns numbers as string
* This is important for big numbers (number > Math.pow(2, 53)) as js numbers
* are 64bit floating point numbers with reduced precision
*
* @param parser

@@ -121,5 +128,2 @@ * @returns {*}

function parseInteger (parser) {
// If stringNumbers is activated the parser always returns numbers as string
// This is important for big numbers (number > Math.pow(2, 53)) as js numbers
// are 64bit floating point numbers with reduced precision
if (parser.optionStringNumbers) {

@@ -230,3 +234,6 @@ return parseStringNumbers(parser)

default:
return handleError(parser, new ReplyError('Protocol error, got ' + JSON.stringify(String.fromCharCode(type)) + ' as reply type byte'))
const err = new ReplyError('Protocol error, got ' + JSON.stringify(String.fromCharCode(type)) + ' as reply type byte', 20)
err.offset = parser.offset
err.buffer = JSON.stringify(parser.buffer)
return handleError(parser, err)
}

@@ -258,3 +265,3 @@ }

for (var key in options) {
if (typeof options[key] !== optionTypes[key]) {
if (optionTypes.hasOwnProperty(key) && typeof options[key] !== optionTypes[key]) {
throw new TypeError('The options argument contains the property "' + key + '" that is either unkown or of a wrong type')

@@ -289,2 +296,7 @@ }

* Concat a bulk string containing multiple chunks
*
* Notes:
* 1) The first chunk might contain the whole bulk string including the \r
* 2) We are only safe to fully add up elements that are neither the first nor any of the last two elements
*
* @param parser

@@ -296,3 +308,2 @@ * @param buffer

var list = parser.bufferCache
// The first chunk might contain the whole bulk string including the \r
var chunks = list.length

@@ -310,3 +321,2 @@ var offset = parser.bigStrSize - parser.totalChunkSize

for (var i = 1; i < chunks - 2; i++) {
// We are only safe to fully add up elements that are neither the first nor any of the last two elements
res += decoder.write(list[i])

@@ -326,4 +336,10 @@ }

if (counter === 1 || notDecreased > counter * 2) {
// Decrease the bufferPool by 16kb by removing the first 16kb of the current pool
bufferPool = bufferPool.slice(Math.floor(bufferPool.length / 10), bufferPool.length)
// Decrease the bufferPool by 10% by removing the first 10% of the current pool
var sliceLength = Math.floor(bufferPool.length / 10)
if (bufferOffset <= sliceLength) {
bufferOffset = 0
} else {
bufferOffset -= sliceLength
}
bufferPool = bufferPool.slice(sliceLength, bufferPool.length)
} else {

@@ -352,7 +368,6 @@ notDecreased++

if (bufferPool.length < length + bufferOffset) {
// Increase the bufferPool size by three times the current needed length
var multiplier = 3
if (bufferOffset > 1024 * 1024 * 200) {
// Increase the bufferPool size
var multiplier = length > 1024 * 1024 * 75 ? 2 : 3
if (bufferOffset > 1024 * 1024 * 120) {
bufferOffset = 1024 * 1024 * 50
multiplier = 2
}

@@ -364,3 +379,3 @@ bufferPool = new Buffer(length * multiplier + bufferOffset)

if (interval === null) {
interval = setInterval(decreaseBufferPool, 50)
interval = setInterval(decreaseBufferPool, 50).unref()
}

@@ -384,3 +399,3 @@ }

*/
JavascriptRedisParser.prototype.execute = function (buffer) {
JavascriptRedisParser.prototype.execute = function execute (buffer) {
if (this.buffer === null) {

@@ -426,5 +441,5 @@ this.buffer = buffer

if (type === 45) {
this.returnError(response) // Errors -
this.returnError(response)
} else {
this.returnReply(response) // Strings + // Integers : // Bulk strings $ // Arrays *
this.returnReply(response)
}

@@ -431,0 +446,0 @@ }

@@ -5,5 +5,6 @@ 'use strict'

function ReplyError (message) {
function ReplyError (message, newLimit) {
var limit = Error.stackTraceLimit
Error.stackTraceLimit = 2
Error.stackTraceLimit = newLimit || 2
Error.call(this, message)
Error.captureStackTrace(this, this.constructor)

@@ -10,0 +11,0 @@ Error.stackTraceLimit = limit

{
"name": "redis-parser",
"version": "2.0.4",
"version": "2.1.0",
"description": "Javascript Redis protocol (RESP) parser",

@@ -33,7 +33,7 @@ "main": "index.js",

"benchmark": "^2.1.0",
"codeclimate-test-reporter": "^0.3.1",
"codeclimate-test-reporter": "^0.4.0",
"intercept-stdout": "^0.1.2",
"istanbul": "^0.4.0",
"standard": "^7.0.1",
"mocha": "^2.3.2",
"standard": "^8.5.0",
"mocha": "^3.1.2",
"hiredis": "^0.5.0"

@@ -40,0 +40,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc