Skip to content

Commit fd70b00

Browse files
committed
Add binary deserialization depth limit and swap to Syntax
This change adds the standard protobuf deserialization depth limit of 200. Today, overruns trigger RangeErrors from the VM. We are now catching these and swapping them to SyntaxError.
1 parent a749e29 commit fd70b00

13 files changed

Lines changed: 1101 additions & 145 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ permissions:
88

99
# update in build.yml and codeql.yml at same time
1010
env:
11-
PROTOC_VERSION: "35.1"
11+
PROTOC_VERSION: "36.1"
1212

1313
jobs:
1414
build:

‎MODULE.bazel‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"Bazel module that provides protoc-gen-js."
22

3-
module(name = "protobuf_javascript", version = "4.0.2") # updated by release action
3+
module(name = "protobuf_javascript", version = "4.0.3") # updated by release action
44

55
bazel_dep(name = "abseil-cpp", version = "20250814.1")
66
bazel_dep(name = "protobuf", version = "33.4", repo_name = "com_google_protobuf")

‎MODULE.bazel.lock‎

Lines changed: 5 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎binary/errors.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,26 @@ function negativeByteLengthError(
108108
return new Error(`Tried to read a negative byte length: ${length}`);
109109
}
110110

111+
/**
112+
* Reports that the maximum recursion depth was exceeded.
113+
*
114+
* @return {!SyntaxError}
115+
*/
116+
function maxRecursionDepthExceededError() {
117+
return new SyntaxError('Maximum protobuf recursion depth exceeded');
118+
}
119+
111120
exports = {
112121
messageLengthMismatchError,
113122
groupDidNotEndWithEndGroupError,
114123
invalidFieldNumberError,
115124
invalidVarintError,
116125
invalidWireTypeError,
117126
malformedBinaryBytesForMessageSet,
127+
maxRecursionDepthExceededError,
118128
negativeByteLengthError,
119129
readTooFarError,
120130
unmatchedStartGroupError,
121131
unmatchedStartGroupEofError,
122132
};
133+

0 commit comments

Comments
 (0)