Add files via upload - #22
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: 任何调用 putData 且传入非法索引的代码都会导致运行时异常崩溃。虽然 Java 有边界检查不会造成内存破坏,但会导致服务不可用或数据丢失。
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 >= 4 时(如 line 12 的 putData(5, 100)),line 8 会触发 ArrayIndexOutOfBoundsException。
📍 问题详情
🔴 问题 1 | 严重程度: HIGH | 行号: 8
💬 详细说明:
- 任何调用 putData 且传入非法索引的代码都会导致运行时异常崩溃。虽然 Java 有边界检查不会造成内存破坏,但会导致服务不可用或数据丢失。
📝 问题代码:
store[pos] = num;
💡 修复建议:
在 line 5 的条件中增加上限检查,确保 pos 在 [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.