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

Conversation

bzoz
Copy link
Contributor

@bzoz bzoz commented Aug 2, 2017

Fix a bug when messages bigger than 64kb where incorrectly parsed by the inspector-helper.
See #14507 (comment)

Fixes: #14507

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

test

/cc @eugeneo @nodejs/v8-inspector

Fix a bug when messages bigger than 64kb where incorrectly parsed by
the inspector-helper.

Fixes: nodejs#14507
@bzoz bzoz added the test Issues and PRs related to the tests. label Aug 2, 2017
@bzoz bzoz requested a review from eugeneo August 2, 2017 13:30
@nodejs-github-bot nodejs-github-bot added dont-land-on-v4.x inspector Issues and PRs related to the V8 inspector protocol test Issues and PRs related to the tests. labels Aug 2, 2017
@@ -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

@@ -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
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);

@bzoz
Copy link
Contributor Author

bzoz commented Aug 2, 2017

I've added a test for max message size, PTAL

@@ -68,7 +68,9 @@ function parseWSFrame(buffer, handler) {
dataLen = buffer.readUInt16BE(2);
bodyOffset = 4;
} else if (dataLen === 127) {
dataLen = buffer.readUInt32BE(2);
if (buffer[2] !== 0 || buffer[3] !== 0)
assert.fail('Inspector message to big');
Copy link
Member

Choose a reason for hiding this comment

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

Nit: typo "to" -> "too"

Copy link
Member

Choose a reason for hiding this comment

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

This check can be condensed into a single...

assert(buffer[2] === 0 && buffer[3] === 0, 'Inspector message too big');

Copy link
Contributor

Choose a reason for hiding this comment

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

@Trott
Copy link
Member

Trott commented Aug 2, 2017

CI: https://ci.nodejs.org/job/node-test-pull-request/9451/

Only failure is build/infra related. CI is effectively green.

Copy link
Contributor

@refack refack left a comment

Choose a reason for hiding this comment

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

LGTM % nits

@@ -68,7 +68,9 @@ function parseWSFrame(buffer, handler) {
dataLen = buffer.readUInt16BE(2);
bodyOffset = 4;
} else if (dataLen === 127) {
dataLen = buffer.readUInt32BE(2);
if (buffer[2] !== 0 || buffer[3] !== 0)
assert.fail('Inspector message to big');
Copy link
Contributor

Choose a reason for hiding this comment

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

@Trott
Copy link
Member

Trott commented Aug 3, 2017

Given the frequency that the test is failing on CI, I'd like to land this now-ish. Anyone else feel the same?

@bzoz
Copy link
Contributor Author

bzoz commented Aug 4, 2017

I've fixed the spelling, changed assert per @jasnell suggestion and added @refack link, PTAL

@bzoz
Copy link
Contributor Author

bzoz commented Aug 4, 2017

CI (its still "pending", I think this is the correct one): https://ci.nodejs.org/job/node-test-pull-request/9483/

@refack
Copy link
Contributor

refack commented Aug 4, 2017

last CI cancelled.
new CI: https://ci.nodejs.org/job/node-test-pull-request/9483/

@Trott
Copy link
Member

Trott commented Aug 4, 2017

Only failure in CI is a known flaky unrelated to this. CI is effectively green. Landing...

Trott pushed a commit to Trott/io.js that referenced this pull request Aug 4, 2017
Fix a bug when messages bigger than 64kb where incorrectly parsed by
the inspector-helper.

PR-URL: nodejs#14596
Fixes: nodejs#14507
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@Trott
Copy link
Member

Trott commented Aug 4, 2017

Landed in 2dc09f6. 🎉

@Trott Trott closed this Aug 4, 2017
@refack
Copy link
Contributor

refack commented Aug 4, 2017

AIX fail is a known flake and is unrelated #14599 -
https://ci.nodejs.org/job/node-test-commit-aix/7643/nodes=aix61-ppc64/

@MylesBorins MylesBorins mentioned this pull request Aug 8, 2017
addaleax pushed a commit that referenced this pull request Aug 10, 2017
Fix a bug when messages bigger than 64kb where incorrectly parsed by
the inspector-helper.

PR-URL: #14596
Fixes: #14507
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@addaleax addaleax mentioned this pull request Aug 13, 2017
MylesBorins pushed a commit that referenced this pull request Sep 19, 2017
Fix a bug when messages bigger than 64kb where incorrectly parsed by
the inspector-helper.

PR-URL: #14596
Fixes: #14507
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Sep 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inspector Issues and PRs related to the V8 inspector protocol test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

investigate flaky test-inspector-stop-profile-after-done on Windows
10 participants