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

test: read proper inspector message size #14596

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/inspector/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function parseWSFrame(buffer, handler) {
dataLen = buffer.readUInt16BE(2);
bodyOffset = 4;
} else if (dataLen === 127) {
dataLen = buffer.readUInt32BE(2);
dataLen = buffer.readUIntBE(2, 8);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: the docs for buf.readUIntBE() state that the second argument Must satisfy: 0 < byteLength <= 6

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, byteLength can only go up to 6 for a total of 48 bits.
Should we split the read into two chunks, 4 bytes each? Like

dataLen = buffer.readUInt32BE(2);
if (dataLen > Math.pow(2, 53 - 32) - 1) {
  assert.fail('Frame size is bigger than `Number.MAX_SAFE_INTEGER`');
}
dataLen += buffer.readUInt32BE(6);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be easier to assert that buffer[1] and buffer[2] equal 0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, the max value for a UInt32 is 4294967295, vastly lower than Number.MAX_SAFE_INTEGER, so the if check is not needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Trott yes but dataLen === 127 means that the frame size is a 64 bit int.

Copy link
Member

@lpinca lpinca Aug 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's safe to assume that frames are not bigger than 2 ** 32 -1 😄 (I'm not sure how they are generated). In that case we can ignore the first 4 bytes:

dataLen = buffer.readUInt32BE(6);

bodyOffset = 10;
}
if (buffer.length < bodyOffset + dataLen)
Expand Down