From b48b937f268c84419c8bad4c3fc7ee5b71b56535 Mon Sep 17 00:00:00 2001 From: Hugh O'Brien Date: Tue, 25 Aug 2020 14:09:22 +0100 Subject: [PATCH] Merge pull request #3133 from overleaf/hb-fix-bibtex-error-crash Stop bib log parser after 500 iterations per parser GitOrigin-RevId: 415624c20154b4fd4054f166179cd455a7cc2d4d --- .../js/ide/pdf/controllers/PdfController.js | 2 +- .../web/frontend/js/vendor/libs/bib-log-parser.js | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/services/web/frontend/js/ide/pdf/controllers/PdfController.js b/services/web/frontend/js/ide/pdf/controllers/PdfController.js index 95a2a52293..0dc603c397 100644 --- a/services/web/frontend/js/ide/pdf/controllers/PdfController.js +++ b/services/web/frontend/js/ide/pdf/controllers/PdfController.js @@ -615,7 +615,7 @@ App.controller('PdfController', function( function processBiber(log) { const { errors, warnings } = BibLogParser.parse(log, {}) const all = [].concat(errors, warnings) - accumulateResults({ type: 'BibTeX', all, errors, warnings }) + accumulateResults({ type: 'BibTeX:', all, errors, warnings }) } // output the results diff --git a/services/web/frontend/js/vendor/libs/bib-log-parser.js b/services/web/frontend/js/vendor/libs/bib-log-parser.js index a8326840b6..04afbf0d97 100644 --- a/services/web/frontend/js/vendor/libs/bib-log-parser.js +++ b/services/web/frontend/js/vendor/libs/bib-log-parser.js @@ -23,10 +23,19 @@ define(function() { iterationCount = 0; while (match = re.exec(text)) { iterationCount += 1; - if (iterationCount >= 10000) { - return result; - } newEntry = process(match); + + // Too many log entries can cause browser crashes + // Construct a too many files error from the last match + const maxErrors = 100 + if (iterationCount >= maxErrors) { + const level = newEntry.level + "s" + newEntry.message = `Over ${maxErrors} ${level} returned. Download raw logs to see full list`; + newEntry.line = undefined; + result.unshift(newEntry) + return [result, ""]; + } + result.push(newEntry); text = (match.input.slice(0, match.index)) + (match.input.slice(match.index + match[0].length + 1, match.input.length)); }