[Bug] Shiro1CryptFormat.parse() throws ArrayIndexOutOfBoundsException for malformed hashes

未关闭 适合新手
#2,967 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java

调研方向

Shiro1CryptFormat 位于 crypto/hash 模块下(shiro-core 中的模块 lang/crypto 包);打开 parse(String) 方法,跟踪它如何按 $ 拆分并用索引反向遍历各部分。运行 issue 中四个失败的输入以确认 AIOOBE,然后在任何索引操作之前添加一个长度保护,抛出 IllegalArgumentException("The argument is not a valid 'shiro1' formatted hash.")。完成的样子是四个代码片段都抛出 IAE,并且现有的 Shiro1CryptFormat 单元测试仍然通过。

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

描述

Search before asking
Environment

Not environment-specific: the bug is in pure string-parsing logic, so it happens on any OS/JDK.

Shiro version

main branch (commit ea33e99)

What was the actual outcome?

Shiro1CryptFormat.parse(String) throws ArrayIndexOutOfBoundsException when a $shiro1$ hash is missing one or more of its $-separated parts. The method counts backwards through the parts without checking how many there are.

What was the expected outcome?

IllegalArgumentException("The argument is not a valid 'shiro1' formatted hash."), the same exception the method already throws for an invalid prefix or non-numeric iterations.

How to reproduce
new Shiro1CryptFormat().parse("$shiro1$SHA-256");      // AIOOBE: Index -1 out of bounds for length 1
new Shiro1CryptFormat().parse("$shiro1$SHA-256$");     // AIOOBE
new Shiro1CryptFormat().parse("$shiro1$SHA-256$abc");  // AIOOBE
new Shiro1CryptFormat().parse("$shiro1$SHA-256$1$$");  // AIOOBE
Debug logs

No response

主要语言
Java
星标
4.5k
派生
2.3k
平均合并
1 天 5 分钟
30 天内合并 PR
27

环境准备

从这里开始

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

apache/shiro 的其他 Issue

查看 apache/shiro 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

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