Conversation
`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>
Codecov Report❌ Patch coverage is
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
🚀 New features to boost your workflow:
|
meixg
reviewed
Sep 18, 2026
jasnell
commented
Sep 18, 2026
Co-authored-by: James M Snell <jasnell@gmail.com>
meixg
approved these changes
Sep 18, 2026
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.