Possible error in lexer.go

未关闭
#97 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@AdamMagued 已经在做这个了。

开始于 2026年10月10日。

  • #104 来自 @AdamMagued —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
go
领域
compilers

调研方向

从 lexer.go 中大约第 389 行的 consumeUnquotedIdentifier 开始,使用 r = 128 重现所提供的 Go 示例。确认 lexer 对该输入不再发生 panic,同时保留预期的标识符扫描行为。

由索引模型根据 Issue 内容生成。

描述

Hi!
I checked my project, which has the go-jmespath library in its dependencies, with the SAST tool and found some problems in the go-jmespath code.

On line 389, SAST was triggered by a possible index out of range problem.

func (lexer *Lexer) consumeUnquotedIdentifier() token {
	// Consume runes until we reach the end of an unquoted
	// identifier.
	start := lexer.currentPos - lexer.lastWidth
	for {
		r := lexer.next()
		if r < 0 || r > 128 || identifierTrailingBits[uint64(r)/64]&(1<<(uint64(r)%64)) == 0 {
			lexer.back()
			break
		}
	}
	value := lexer.expression[start:lexer.currentPos]
	return token{
		tokenType: tUnquotedIdentifier,
		value:     value,
		position:  start,
		length:    lexer.currentPos - start,
	}
}

I found that when r = 128 a panic occurs

package main

import "fmt"

func main() {
	var identifierTrailingBits = [2]uint64{287948901175001088, 576460745995190270}

	var r rune = 128
	if r < 0 || r > 128 || identifierTrailingBits[uint64(r)/64]&(1<<(uint64(r)%64)) == 0 {
		fmt.Println("yes")
	} else {
		fmt.Println("no")
	}
}

result

panic: runtime error: index out of range [2] with length 2
主要语言
Go
星标
623
派生
105
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

jmespath/go-jmespath 的其他 Issue

查看 jmespath/go-jmespath 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。