Skip to content

fix(datamodel/low): make NodeLines nil-safe to stop panics on skipped external refs - #707

Open
swayam5342 wants to merge 1 commit into
pb33f:mainfrom
swayam5342:fix/nil-nodelines-skip-external-refs
Open

swayam5342 wants to merge 1 commit into
pb33f:mainfrom
swayam5342:fix/nil-nodelines-skip-external-refs

Conversation

@swayam5342

Copy link
Copy Markdown

Fixes #705.

With SkipExternalRefResolution enabled, an external $ref used as a map entry (a media type, header, link, example, encoding, callback or webhook) is replaced in ExtractMapExtensions by a placeholder that is never built, so its Nodes store is nil. The parent's Build then calls v.Value.Nodes.Store(...) on it, which panics in (*NodeLines).write. The panic happens on a TranslateSliceParallel goroutine, so callers can't recover it and the process exits.

This affects 12 of the 13 v.Value.Nodes.Store loops in datamodel/low/v3. With resolution not skipped, the same documents return an error, as before. The bug has been present since SkipExternalRefResolution was added in 1b522c2 (first released in v0.33.4).

Change

*NodeLines is now safe to use through a nil pointer: write (and so Store and add) does nothing, Load reports not-found, and Range visits nothing. NodeMap.GetNodes and GetNodeLines already accept a nil store, so this extends the same contract to the rest of the type and fixes every call site in one place. Objects that were built have a non-nil store, so their behavior doesn't change.

Tests

  • TestNodeLines_NilReceiver: the nil-store contract.
  • TestSkipExternalRefResolution_ExternalRefMapEntriesDoNotPanic: one document per affected map, built with SkipExternalRefResolution: true. Without this change the test binary crashes; with it, all 12 cases build without error.

go test ./... on Windows (go1.27.0): 33 packages pass. TestRolodex_SimpleTest_OneDoc and TestSpecIndex_BurgerShopMixedRef (index), and FuzzAppendJSONString seed #5 (json), fail with identical output on unmodified main on the same machine, so they're unrelated to this change. They look like Windows-specific byte counts.

Possible follow-up

Kept out of this PR because it changes behavior library-wide: recovering panics inside the TranslateSliceParallel workers and returning them as errors, so a future bug of this kind can't take down the host process.

@codecov

codecov Bot commented Nov 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (88615e4) to head (d4f4059).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #707   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          315       315           
  Lines        39758     39764    +6     
=========================================
+ Hits         39758     39764    +6     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@daveshanley daveshanley left a comment

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.

LGTM, thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unrecoverable nil pointer panic in (*v3.RequestBody).Build when content has a null media type next to a $ref one

2 participants