Skip to content

Commit

Permalink
fix: possible infinite loop when parsing option
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-fenster committed Aug 17, 2023
1 parent 42e5a9c commit 05626e3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions bench/prof.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ function setupBrowser() {
switch (process.argv[2]) {
case "encode-browser":
setupBrowser();
// eslint-disable-line no-fallthrough
// eslint-disable-next-line no-fallthrough
case "encode":
for (var i = 0; i < count; ++i)
Test.encode(data).finish();
break;
case "decode-browser":
setupBrowser();
// eslint-disable-line no-fallthrough
// eslint-disable-next-line no-fallthrough
case "decode":
var buf = Test.encode(data).finish();
for (var j = 0; j < count; ++j)
Expand Down
2 changes: 1 addition & 1 deletion cli/lib/tsd-jsdoc/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ function handleElement(element, parent) {
handleEnum(element, parent);
break;
}
// eslint-disable-line no-fallthrough
// eslint-disable-next-line no-fallthrough
case "namespace":
handleNamespace(element, parent);
break;
Expand Down
4 changes: 2 additions & 2 deletions src/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
break;
case "uint64":
isUnsigned = true;
// eslint-disable-line no-fallthrough
// eslint-disable-next-line no-fallthrough
case "int64":
case "sint64":
case "fixed64":
Expand Down Expand Up @@ -176,7 +176,7 @@ function genValuePartial_toObject(gen, field, fieldIndex, prop) {
break;
case "uint64":
isUnsigned = true;
// eslint-disable-line no-fallthrough
// eslint-disable-next-line no-fallthrough
case "int64":
case "sint64":
case "fixed64":
Expand Down
9 changes: 7 additions & 2 deletions src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function parse(source, root, options) {
break;
case "public":
next();
// eslint-disable-line no-fallthrough
// eslint-disable-next-line no-fallthrough
default:
whichImports = imports || (imports = []);
break;
Expand Down Expand Up @@ -286,8 +286,10 @@ function parse(source, root, options) {
}
if (skip("{", true)) {
var token;
while ((token = next()) !== "}")
while ((token = next()) !== "}") {
console.log("token:", token);
fnIf(token);
}
skip(";", true);
} else {
if (fnElse)
Expand Down Expand Up @@ -621,6 +623,9 @@ function parse(source, root, options) {
if (!nameRe.test(token = next())) {
throw illegal(token, "name");
}
if (token === null) {
throw illegal(token, "end of input");
}

var value;
var propName = token;
Expand Down
4 changes: 1 addition & 3 deletions tests/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,14 @@ tape.test("pbjs generates static code with message filter", function (test) {
var $protobuf = protobuf;
eval(jsCode);

console.log(protobuf.roots);

var NeedMessage1 = protobuf.roots.default.filtertest.NeedMessage1;
var NeedMessage2 = protobuf.roots.default.filtertest.NeedMessage2;
var DependentMessage1 = protobuf.roots.default.filtertest.DependentMessage1;
var DependentMessageFromImport = protobuf.roots.default.DependentMessageFromImport;

var NotNeedMessageInRootFile = protobuf.roots.default.filtertest.NotNeedMessageInRootFile;
var NotNeedMessageInImportFile = protobuf.roots.default.NotNeedMessageInImportFile;

test.ok(NeedMessage1, "NeedMessage1 is loaded");
test.ok(NeedMessage2, "NeedMessage2 is loaded");
test.ok(DependentMessage1, "DependentMessage1 is loaded");
Expand Down
5 changes: 5 additions & 0 deletions tests/comp_options-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,10 @@ tape.test("Options", function (test) {
test.end();
});

test.test(test.name + " - invalid option", function (test) {
test.throws(() => { protobuf.parse("option (foo).whatever = {")});
test.end();
});

test.end();
});

0 comments on commit 05626e3

Please sign in to comment.