Add files via upload - #20
Open
joyfaker wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
AI代码审查报告
变更概览
本次 PR 涉及 1 个文件,新增 +14 行,删除 -0 行。
功能变更摘要
该PR新增了一个用于演示数组越界漏洞的示例类。代码仅校验了负数索引,未限制最大索引范围,并在主函数中故意传入越界参数以触发运行时异常。此变更主要用于静态分析工具测试、代码审计教学或边界条件校验的缺陷演示。
文件变更摘要
| 文件 | 变更 | 行数 | 摘要 | 发现问题 |
|---|---|---|---|---|
BadArray.java |
新增 | +14/-0 | 新增演示数组越界缺陷的示例类,仅校验负数索引而忽略上限检查,主函数故意传入越界参数以触发异常。 | 1 个 |
问题严重级别分布
| 级别 | 数量 | 占比 |
|---|---|---|
| 🔴 高危 | 1 | 100% |
代表性问题(至多 10 条,按严重级别优先)
- 🔴 高危
BadArray.javaL8: 攻击者或错误输入可触发运行时异常,导致服务崩溃或不可用。在更复杂的场景中,若此类逻辑存在于关键业务路径,可能引发拒绝服务(DoS)。
Powered by: qwen3.6-plus
由 CodeHawk 提供支持 · nuwa
| if (pos < 0) { | ||
| return; | ||
| } | ||
| store[pos] = num; |
There was a problem hiding this comment.
🔴 AI 代码审查发现问题
📋 问题概述
数组索引校验不完整导致越界写入
line 5-7 仅检查了 pos < 0 的情况并返回,但未检查 pos >= store.length 的上限。当传入 pos = 5(如 line 12 所示)时,程序会尝试访问 store[5],而数组长度仅为 4(line 2),导致 ArrayIndexOutOfBoundsException。
📍 问题详情
🔴 问题 1 | 严重程度: HIGH | 行号: 8
💬 详细说明:
- 攻击者或错误输入可触发运行时异常,导致服务崩溃或不可用。在更复杂的场景中,若此类逻辑存在于关键业务路径,可能引发拒绝服务(DoS)。
📝 问题代码:
store[pos] = num;
💡 修复建议:
在写入数组前增加上限校验,确保索引在 [0, store.length) 范围内。
✅ 修复示例:
public static void putData(int pos, int num) {
if (pos < 0 || pos >= store.length) {
return;
}
store[pos] = num;
}
🔗 参考链接
无
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.