From 81e06ce58a3a4a09b7c6c2837e8076ecec6e38e3 Mon Sep 17 00:00:00 2001 From: cel Date: Sat, 3 Jun 2017 12:16:56 -1000 Subject: Protect against too much recursion --- lib/git.js | 11 ++++++++--- package.json | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/git.js b/lib/git.js index 1360a6f..d4a071e 100644 --- a/lib/git.js +++ b/lib/git.js @@ -7,6 +7,7 @@ var packidx = require('pull-git-packidx-parser') var Reader = require('pull-reader') var toPull = require('stream-to-pull-stream') var zlib = require('zlib') +var looper = require('looper') var ObjectNotFoundError = u.customError('ObjectNotFoundError') @@ -501,12 +502,16 @@ Git.prototype.getTag = function (obj, cb) { function readCString(reader, cb) { var chars = [] - reader.read(1, function next(err, ch) { + var loop = looper(function () { + reader.read(1, next) + }) + function next(err, ch) { if (err) return cb(err) if (ch[0] === 0) return cb(null, Buffer.concat(chars).toString('utf8')) chars.push(ch) - reader.read(1, next) - }) + loop() + } + loop() } Git.prototype.readTree = function (obj) { diff --git a/package.json b/package.json index 465e93f..42311a4 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "human-time": "^0.0.1", "hyperscript": "^2.0.2", "hashlru": "^2.1.0", + "looper": "^4.0.0", "mime-types": "^2.1.12", "multicb": "^1.2.1", "pull-cat": "^1.1.11", -- cgit v1.2.3