fix: node --line wraps a value above the int32 range and selects the wrong definition
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 80/100
Hướng nghiên cứu
Đọc internal/cli/node.go:91 nơi --line được khai báo là int, sau đó là đoạn chuyển tiếp ở các dòng 38-40, và internal/query/node.go:287 nơi nó được ép kiểu sang int32 trước phép so sánh StartLine/EndLine ở dòng 294. Thêm kiểm tra phạm vi (1 đến 2147483647) tại flag hoặc tại biên truy vấn, trả về lỗi có nêu phạm vi; đừng cố làm cho narrowNodeMatches trả về rỗng. Mở rộng internal/query/node_test.go bên cạnh TestNarrowNeverEmpty với một trường hợp ngoài phạm vi. Hoàn thành nghĩa là một giá trị ngoài phạm vi báo lỗi thay vì bị wrap.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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:91declares--lineas anint. When the value is not 0, lines 38-40 pass the pointer on.internal/query/node.go:287runsline := int32(*lineHint).internal/query/node.go:294compares that value withStartLineandEndLine, which areint32(internal/schema/graph.pb.go:112-113).- When no definition contains the line,
internal/query/node.go:301-303picks the nearest definition.
Reading the code gives these results. The binary was not run.
--line 4294967302(2^32 + 6) becomes6and selects the definition at line 6.--line 4294967296(2^32) becomes0. The pointer is not nil, so the nearest-line path picks one definition.--line 0shows 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.
cd <repo>where a symbol has two or more definitions.- Run
codegraph node <symbol> --line 4294967302. - 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.
- Ngôn ngữ chính
- Go
- Star
- 0
- Fork
- 0
- Merge trung bình
- 7 giờ 42 phút
- Pull request đã merge (30 ngày)
- 111
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của seanb4t/codegraph-go
-
chore needs-triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
seanb4t/codegraph-go#380 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
chore needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
seanb4t/codegraph-go#379 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:query chore needs-triage spec-needed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
seanb4t/codegraph-go#377 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
chore needs-triage
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 84/100
seanb4t/codegraph-go#362 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:ci chore priority:low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
seanb4t/codegraph-go#329 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của seanb4t/codegraph-go
Issue tương tự
-
Add iterate GmbH domains to a dedicated list and include it in company and developer categoriesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
v2fly/domain-list-community#4307 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 1 ngày
-
notify: voice_queue rows are deleted only at startup, so a hub that stays up grows it without boundĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
mattabate/life-distributable#232 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày