Skip to content

inspector: fix ctype UB and stoi overflow in session id parsing - #65763

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
VirajMishra1:fix-misc-safety-bugs
Dec 4, 2026
Merged

nodejs-github-bot merged 1 commit into
nodejs:mainfrom
VirajMishra1:fix-misc-safety-bugs

Conversation

@VirajMishra1

@VirajMishra1 VirajMishra1 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes three small issues in how the inspector parses the target session id in inspector_io.cc:

  • The ::isdigit call now takes an unsigned char. Passing a plain char is undefined behavior when the value is negative, which happens with non-ASCII input.
  • std::stoi is replaced with std::from_chars. The string is already checked to be all digits, so the only difference is overflow: stoi throws, which doesn't build with -fno-exceptions, and from_chars reports an error code that we now check.
  • target_session_id is cast to unsigned int before the << 16, since left-shifting a large signed value is undefined behavior.

This PR also used to fix the WebSocket frame bounds check in inspector_socket.cc, but that was fixed on main in 93df195, so I dropped it when rebasing.

I used AI tooling to help find these and draft the first version. I reviewed and understand each change and I am responsible for it.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/inspector
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Sep 3, 2026
@MikeMcC399

Copy link
Copy Markdown
Member

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.

@MikeMcC399

Copy link
Copy Markdown
Member

Please make sure you have read and understood the following documents:

@VirajMishra1

Copy link
Copy Markdown
Contributor Author

I have read and understood all of the linked documents -- the contributing guide, pull request guide, AI use policy, automation policy, and Code of Conduct.

To be transparent: I used AI tooling to help identify these bugs and draft the initial code, but I personally reviewed each change, understand what it does, and take responsibility for it. I did not use automated tooling to open this PR -- I opened it manually after reviewing the diff. Happy to discuss any of the specific changes if that would help.

@MikeMcC399

This comment was marked as resolved.

@VirajMishra1
VirajMishra1 force-pushed the fix-misc-safety-bugs branch 2 times, most recently from 669354e to 9d651d8 Compare September 3, 2026 18:08
@VirajMishra1

Copy link
Copy Markdown
Contributor Author

Thanks for checking. Two CI failures, both now fixed:

  1. Build failures (inspector_io.cc): The try/catch around std::stoi doesn't compile when -fno-exceptions is set. Replaced with std::from_chars (C++17, no exceptions needed, same overflow-safe behavior).

  2. Commit message lint: The title used fix: which isn't a valid Node.js subsystem prefix. Amended to inspector,http,os: fix ctype UB, stoi overflow, proto pollution (within 72 chars, valid subsystems, with Signed-off-by trailer).

Force-pushed the updated commit. CI should be clean now.

Comment thread lib/_http_outgoing.js Outdated

const headersMap = this[kOutHeaders];
const headers = {};
const headers = { __proto__: null };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this alone would likely need a full http CI benchmark

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I reverted it for now, happy to revisit in a separate PR with benchmarks.

@codecov

codecov Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.59%. Comparing base (a055d9f) to head (71ba7c0).
⚠️ Report is 194 commits behind head on main.

Files with missing lines Patch % Lines
src/inspector_io.cc 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65763      +/-   ##
==========================================
+ Coverage   90.52%   90.59%   +0.07%     
==========================================
  Files         803      802       -1     
  Lines      285110   286660    +1550     
  Branches    55037    55372     +335     
==========================================
+ Hits       258101   259705    +1604     
+ Misses      17143    17061      -82     
- Partials     9866     9894      +28     
Files with missing lines Coverage Δ
src/inspector_io.cc 91.16% <85.71%> (-0.64%) ⬇️

... and 145 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

MikeMcC399

This comment was marked as resolved.

@legendecas legendecas added the inspector Issues and PRs related to the V8 inspector protocol. label Sep 7, 2026
@VirajMishra1 VirajMishra1 changed the title fix: ctype UB, WebSocket over-read, stoi crash, signed shift UB, proto pollution inspector: fix ctype UB, stoi overflow, WebSocket frame bounds Sep 7, 2026
@VirajMishra1

Copy link
Copy Markdown
Contributor Author

Thanks for flagging this. The mismatch was from before I replaced stoi with from_chars and dropped the http change. The title and the commit message are now the same, and I have updated the description so it lists the four changes actually in the diff and describes the frame bounds check correctly.

@MikeMcC399

This comment was marked as resolved.

- cast the isdigit argument to unsigned char, since passing a negative
  char is undefined behavior
- replace stoi with from_chars, since stoi throws on overflow and the
  build uses -fno-exceptions
- cast to unsigned int before the left shift, since shifting a large
  signed value is undefined behavior

Signed-off-by: VirajMishra1 <viraj.mishra.81@gmail.com>
@VirajMishra1 VirajMishra1 changed the title inspector: fix ctype UB, stoi overflow, WebSocket frame bounds inspector: fix ctype UB and stoi overflow in session id parsing Dec 1, 2026
@VirajMishra1

Copy link
Copy Markdown
Contributor Author

Rebased on main. The WebSocket frame bounds part was already fixed on main in 93df195, so I dropped it and updated the title and description. The PR now only touches the session id parsing in inspector_io.cc.

@legendecas legendecas added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Dec 2, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Dec 2, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@legendecas legendecas added author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue PRs queued for automated landing through the Commit Queue. labels Dec 4, 2026
@nodejs-github-bot
nodejs-github-bot merged commit f97d451 into nodejs:main Dec 4, 2026
68 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in f97d451

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. c++ Issues and PRs that require attention from people who are familiar with C++. inspector Issues and PRs related to the V8 inspector protocol. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants