mirror of
https://github.com/lukaszraczylo/filepuff-mcp.git
synced 2026-10-14 05:30:19 +00:00
fix(parser): guard FindNodeAtPosition against position underflow
line/col are 1-indexed and converted via uint32(line-1); a caller passing 0 wrapped to 4294967295, feeding a garbage Point into tree-sitter. Reachable from the LSP-down AST fallback with caller-supplied coordinates. Reject non-positive positions up front. Adds tests (the function was previously 0% covered).
This commit is contained in:
@@ -16,6 +16,14 @@ func FindNodeAtPosition(tree *sitter.Tree, line, col int) *sitter.Node {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Positions are 1-indexed; reject non-positive values so the uint32
|
||||
// conversion below can't underflow to a huge Row/Column (line/col == 0
|
||||
// would wrap to 4294967295). Reachable from the LSP-down AST fallback with
|
||||
// caller-supplied coordinates.
|
||||
if line < 1 || col < 1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Convert to 0-indexed
|
||||
point := sitter.Point{
|
||||
Row: uint32(line - 1), // #nosec G115 - line numbers are bounded by file size
|
||||
|
||||
Reference in New Issue
Block a user