fix: node --line wraps a value above the int32 range and selects the wrong definition

Open Beginner friendly
#355 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
80/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
cli

Research direction

Read internal/cli/node.go:91 where --line is declared as an int, then the pass-through at lines 38-40, and internal/query/node.go:287 where it is cast to int32 before the StartLine/EndLine comparison at line 294. Add a range check (1 to 2147483647) either at the flag or the query boundary, returning an error that names the range; do not try to make narrowNodeMatches return empty. Extend internal/query/node_test.go next to TestNarrowNeverEmpty with an out-of-range case. Done means an out-of-range value errors instead of wrapping.

Written by the indexing model from the issue text.

Description

area:query bug priority:low spec-needed
What happens

codegraph node --line converts the flag value to int32 with no range check. A value above the int32 range wraps around and selects the wrong definition.

The source shows the path:

  • internal/cli/node.go:91 declares --line as an int. When the value is not 0, lines 38-40 pass the pointer on.
  • internal/query/node.go:287 runs line := int32(*lineHint).
  • internal/query/node.go:294 compares that value with StartLine and EndLine, which are int32 (internal/schema/graph.pb.go:112-113).
  • When no definition contains the line, internal/query/node.go:301-303 picks the nearest definition.

Reading the code gives these results. The binary was not run.

  • --line 4294967302 (2^32 + 6) becomes 6 and selects the definition at line 6.
  • --line 4294967296 (2^32) becomes 0. The pointer is not nil, so the nearest-line path picks one definition. --line 0 shows all definitions.
  • Values from 2147483648 (2^31) upward wrap to negative numbers.

Neither caller, NodeSelected (internal/query/node.go:378) nor NodeDetailSelected (internal/query/detail.go:307), checks the range.

What you expected instead

The command must return an error for a line outside 1 to 2147483647. The error must name that range.

An empty result is not the fix. narrowNodeMatches never returns an empty set by design (internal/query/node.go:266-268), so the check belongs at the flag or query boundary.

Steps to reproduce

Not run. These steps follow from the code and need a check on a built binary.

  1. cd <repo> where a symbol has two or more definitions.
  2. Run codegraph node <symbol> --line 4294967302.
  3. Run codegraph node <symbol> --line 6. If the definition at line 6 is the same, both commands print it.
Version

Not run on a built binary. The source was read at main commit f17af677, after tag v0.19.2.

Platform

Not applicable. The defect is in flag handling, found by reading the source.

How did you install it?

Other

Languages in the affected repository

Not applicable. The bug is in --line handling, not in per-language extraction.

Before submitting
  • I searched existing issues and this is not a duplicate
  • I checked the capability matrix and this is not a documented limitation
  • This is not a security vulnerability

Related: the node-only-line-flag proposal (#350, for #323) listed the 32-bit overflow as out of scope. The spec for --line (openspec/specs/graph-queries/spec.md:228-245) states no range.

Tests: TestNarrowNeverEmpty (internal/query/node_test.go:204) uses lines 22 and 35. TestLineFlagOnlyOnNode (internal/cli/overloads_cli_test.go:49) checks only which commands have the flag. No test covers an out-of-range value.

Dominant language
Go
Stars
0
Forks
0
Avg merge
5h 16m
Merged PRs (30d)
107

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from seanb4t/codegraph-go

All issues in seanb4t/codegraph-go

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.