Repository navigation
buffer: prevent assertion crash in indexOf when encoding is non-numeric - #67050
nikolas-sapa wants to merge 1 commit into
Conversation
|
Welcome to Node.js, and thank you for your first contribution! Before review, please take a moment to read:
Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal. Caution AgentScan found account activity patterns that may be consistent with automation. This is a heuristic, not proof that this pull request was opened by an agent or violates policy. AI-assisted contributions are permitted, but automated tooling must not open pull requests without advance approval, and contributors must personally understand, test, verify, and take responsibility for every submitted change. See the AgentScan analysis, AI use policy, and automation policy for additional context. |
When buf.indexOf(val, offset, encoding) or lastIndexOf/includes was called with a non-string/non-numeric value (such as null or an object) for encoding, end was left as that value instead of defaulting to buffer length. This caused C++ CHECK assertions (args[end_idx]->IsNumber()) to fail and crash the process with SIGABRT. Normalize non-numeric 3rd arguments to buffer length and ensure end is coerced to a number in bidirectionalIndexOf. Signed-off-by: Nik <84yk8btb9f@privaterelay.appleid.com>
fd4dc5c to
6ff7f25
Compare
|
Could a collaborator trigger CI on this when convenient? Small fix with a regression test included. |
When calling
buf.indexOf(val, offset, encoding)(orlastIndexOf/includes) with a non-string and non-numeric value forencoding(such asnullor{}), theendargument is not normalized tothis.lengthbecause the current check only handlestypeof end === 'string'orend === undefined:When
encodingis passed asnullin a 3-argument call (e.g.buf.indexOf(1, 0, null)orbuf.indexOf(Buffer.from('a'), 0, null)),endis passed asnullto the C++ bindings. This triggers fatalCHECKassertion failures (CHECK(args[end_idx]->IsNumber())insrc/node_buffer.cc), aborting the process withSIGABRT(exit code 134):Changes
Buffer.prototype.indexOf,lastIndexOf, andincludes, normalizeendtothis.lengthwhenencoding === undefined && typeof end !== 'number'.bidirectionalIndexOf, defensively normalize non-numericendto a number, defaultingNaNtobuffer.length.test/parallel/test-buffer-indexof-null-encoding.jscovering numeric, buffer, and string targets withnull,{}, andfalseencodings acrossindexOf,lastIndexOf, andincludes.