Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server Reflection - Node.js v22.7.0 RangeError [ERR_BUFFER_OUT_OF_BOUNDS]: "length" is outside of buffer bounds #2820

Open
wavedeck opened this issue Sep 6, 2024 · 1 comment

Comments

@wavedeck
Copy link

wavedeck commented Sep 6, 2024

This is a FYI, easing debugging for other developers trying to use @grpc/reflection specifically with Node.js v22.7.0

Problem description

I wanted to add server reflection with the @grpc/reflection package today and noticed that my application crashed upon it internally trying to create the package definition for the internal reflection.proto file.

After some debugging, I have noticed that the crash is due to a bug in Node.js v22.7.x because the buffer length value is larger than the actual buffer. Updating to Node.js v22.8.0 which was released 3 days ago (September 6th, 2024) fixed the issue and the application doesn't crash anymore.

In Node.js v22.8.0, the buffer length gets truncated instead of trying to read past the buffer preventing a crash.
For the applied fix see nodejs/node#54524

Environment

  • OS name, version and architecture: macOS Sonoma 14.6.1 aarch64
  • Node version: v22.7.0
  • Node installation method: fnm
  • Package name and version: @grpc/[email protected]

Additional context

Stack Trace:

 node:internal/buffer:1066
      throw new ERR_BUFFER_OUT_OF_BOUNDS('length');
RangeError [ERR_BUFFER_OUT_OF_BOUNDS]: "length" is outside of buffer bounds
    at proto.utf8Write (node:internal/buffer:1066:13)
    at Op.writeStringBuffer [as fn] (node_modules/.pnpm/[email protected]/node_modules/protobufjs/src/writer_buffer.js:61:13)
    at BufferWriter.finish (node_modules/.pnpm/[email protected]/node_modules/protobufjs/src/writer.js:453:14)
    at node_modules/.pnpm/@[email protected]/node_modules/@grpc/proto-loader/build/src/index.js:177:109
    at Array.map (<anonymous>)
    at createPackageDefinition (node_modules/.pnpm/@[email protected]/node_modules/@grpc/proto-loader/build/src/index.js:177:39)
    at Object.loadSync (node_modules/.pnpm/@[email protected]/node_modules/@grpc/proto-loader/build/src/index.js:223:12)
    at ReflectionV1Implementation.addToServer (node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@grpc/reflection/build/src/implementations/reflection-v1.js:130:43)
    at ReflectionService.addToServer (node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@grpc/reflection/build/src/service.js:29:17)
    at file://dist/index.js:15:12 {
  code: 'ERR_BUFFER_OUT_OF_BOUNDS'
}
@wavedeck
Copy link
Author

wavedeck commented Sep 6, 2024

PS: The current LTS version of Node.js (v20.17.0) is working fine. This is specifically a bug in v22.7.0 that might or might not be worth trying to prevent on the library side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant