test: read proper inspector message size#14596
Conversation
Fix a bug when messages bigger than 64kb where incorrectly parsed by the inspector-helper. Fixes: nodejs#14507
test/inspector/inspector-helper.js
Outdated
| bodyOffset = 4; | ||
| } else if (dataLen === 127) { | ||
| dataLen = buffer.readUInt32BE(2); | ||
| dataLen = buffer.readUIntBE(2, 8); |
There was a problem hiding this comment.
Note: the docs for buf.readUIntBE() state that the second argument Must satisfy: 0 < byteLength <= 6
test/inspector/inspector-helper.js
Outdated
| bodyOffset = 4; | ||
| } else if (dataLen === 127) { | ||
| dataLen = buffer.readUInt32BE(2); | ||
| dataLen = buffer.readUIntBE(2, 8); |
There was a problem hiding this comment.
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);There was a problem hiding this comment.
I think it will be easier to assert that buffer[1] and buffer[2] equal 0
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@Trott yes but dataLen === 127 means that the frame size is a 64 bit int.
There was a problem hiding this comment.
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);|
I've added a test for max message size, PTAL |
test/inspector/inspector-helper.js
Outdated
| } else if (dataLen === 127) { | ||
| dataLen = buffer.readUInt32BE(2); | ||
| if (buffer[2] !== 0 || buffer[3] !== 0) | ||
| assert.fail('Inspector message to big'); |
There was a problem hiding this comment.
This check can be condensed into a single...
assert(buffer[2] === 0 && buffer[3] === 0, 'Inspector message too big');There was a problem hiding this comment.
Could you add a reference to https://tools.ietf.org/html/rfc6455#section-5.2
|
CI: https://ci.nodejs.org/job/node-test-pull-request/9451/ Only failure is build/infra related. CI is effectively green. |
test/inspector/inspector-helper.js
Outdated
| } else if (dataLen === 127) { | ||
| dataLen = buffer.readUInt32BE(2); | ||
| if (buffer[2] !== 0 || buffer[3] !== 0) | ||
| assert.fail('Inspector message to big'); |
There was a problem hiding this comment.
Could you add a reference to https://tools.ietf.org/html/rfc6455#section-5.2
|
Given the frequency that the test is failing on CI, I'd like to land this now-ish. Anyone else feel the same? |
|
CI (its still "pending", I think this is the correct one): https://ci.nodejs.org/job/node-test-pull-request/9483/ |
|
last CI cancelled. |
|
Only failure in CI is a known flaky unrelated to this. CI is effectively green. Landing... |
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>
|
Landed in 2dc09f6. 🎉 |
|
AIX fail is a known flake and is unrelated #14599 - |
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>
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>
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), orvcbuild test(Windows) passesAffected core subsystem(s)
test
/cc @eugeneo @nodejs/v8-inspector