Skip to content

perf_hooks: harden histogram CBOR import validation - #66098

Open
jasnell wants to merge 3 commits into
nodejs:mainfrom
jasnell:jasnell/perf-hooks-histogram-cbor-compat
Open

jasnell wants to merge 3 commits into
nodejs:mainfrom
jasnell:jasnell/perf-hooks-histogram-cbor-compat

Conversation

@jasnell

@jasnell jasnell commented Sep 18, 2026

Copy link
Copy Markdown
Member

The initial implementation of importHistogram() intentionally used a strict version 1 that accepts a limited number of fields to remain as simple as possible for the initial landing. This introduces version 2 which supports optional unknown fields.

`importHistogram()` did not check the CBOR major type of keys and
integer values, so other data items were decoded as integers. It also
accepted duplicate keys, silently truncated integers cast to narrower
types, allowed bucket counts that did not fit into an `int64_t`, and
trusted the total count, min, and max, leaving imported histograms in
an inconsistent state when those were absent or did not match the
counts.

Validate major types and value ranges, reject duplicate keys and
non-increasing sparse count indexes, and derive the total count, min,
and max from the counts when they are absent. A total count that is
present must match the counts. Data produced by `histogram.export()`
is unaffected.

Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
Histograms exported by Node.js v26.9.0 use format version 1, which
rejects unknown keys on import. Adding fields to version 1 data would
therefore break importing it in v26.9.0, even though that release
claims to support version 1.

Introduce format version 2. It has the same layout as version 1, but
unknown keys are ignored on import, so fields can be added to it later
without changing the version again, while older releases reject it
based on the version rather than on the new fields.
`histogram.export()` now produces version 2 data. `importHistogram()`
accepts versions 1 and 2, and imports version 1 data, as well as data
without a version, with the original semantics.

Assisted-by: OpenCode
Signed-off-by: James M Snell <jasnell@gmail.com>
@jasnell jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Sep 18, 2026
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Sep 18, 2026
@codecov

codecov Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.85047% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.27%. Comparing base (6a7f94c) to head (086897f).
⚠️ Report is 24 commits behind head on main.

Files with missing lines Patch % Lines
src/histogram.cc 87.85% 2 Missing and 11 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #66098   +/-   ##
=======================================
  Coverage   90.27%   90.27%           
=======================================
  Files         790      790           
  Lines      271591   271655   +64     
  Branches    51829    51854   +25     
=======================================
+ Hits       245185   245246   +61     
- Misses      16914    16930   +16     
+ Partials     9492     9479   -13     
Files with missing lines Coverage Δ
src/histogram.cc 86.27% <87.85%> (+0.59%) ⬆️

... and 26 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.

Comment thread doc/api/perf_hooks.md Outdated
@jasnell jasnell added the perf_hooks Issues and PRs related to the perf_hooks module and performance measurement APIs. label Sep 18, 2026
Comment thread doc/api/perf_hooks.md Outdated
Co-authored-by: James M Snell <jasnell@gmail.com>
@jasnell jasnell added the commit-queue-squash PRs the Commit Queue should land as one squashed commit. label Sep 18, 2026
@jasnell jasnell 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 Sep 18, 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 Sep 18, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash PRs the Commit Queue should land as one squashed commit. needs-ci PRs that need a full CI run. perf_hooks Issues and PRs related to the perf_hooks module and performance measurement APIs. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants