Skip to content

Add files via upload - #22

Open
joyfaker wants to merge 1 commit into
mainfrom
joyfaker-patch-17
Open

Add files via upload#22
joyfaker wants to merge 1 commit into
mainfrom
joyfaker-patch-17

Conversation

@joyfaker

Copy link
Copy Markdown
Owner

No description provided.

@code-hawk-test code-hawk-test Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI代码审查报告

变更概览

本次 PR 涉及 1 个文件,新增 +14 行,删除 -0 行。

功能变更摘要

该 PR 新增了一个用于演示数组越界访问问题的示例类。代码中仅校验了索引下限而遗漏了上限检查,并在主函数中故意传入越界索引以触发异常。此变更主要用于复现或测试静态代码分析工具对数组越界缺陷的检测能力。

文件变更摘要

文件 变更 行数 摘要 发现问题
BadArray.java 新增 +14/-0 新增演示数组越界缺陷的示例类,仅校验索引负值而遗漏上限检查,主函数故意传入越界参数触发异常。 1 个

问题严重级别分布

级别 数量 占比
🔴 高危 1 100%

代表性问题(至多 10 条,按严重级别优先)

  1. 🔴 高危 BadArray.java L8: 任何调用 putData 且传入非法索引的代码都会导致运行时异常崩溃。虽然 Java 有边界检查不会造成内存破坏,但会导致服务不可用或数据丢失。

Powered by: qwen3.6-plus


CodeHawk 提供支持 · nuwa

Comment thread BadArray.java
if (pos < 0) {
return;
}
store[pos] = num;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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;
    }

🔗 参考链接

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant