From d60eeadd72c010495fa19d678cc76cadf8ed2d55 Mon Sep 17 00:00:00 2001 From: hjjj1 <2657916031@qq.com> Date: Wed, 3 Jun 2026 09:34:16 +0800 Subject: [PATCH 1/5] Add divide function for Graphite review demo --- calc.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/calc.py b/calc.py index 758bc87..ac6e645 100644 --- a/calc.py +++ b/calc.py @@ -165,3 +165,7 @@ def run(self): if __name__ == "__main__": calc = Calculator() calc.run() + + +def divide(a, b): + return a / b \ No newline at end of file From ec3a0d7fc11ddb6dadeba6f25499f24d7fb2e03e Mon Sep 17 00:00:00 2001 From: hjjj1 <2657916031@qq.com> Date: Wed, 3 Jun 2026 12:11:00 +0800 Subject: [PATCH 2/5] Add unsafe expression evaluation for review demo --- calc.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/calc.py b/calc.py index ac6e645..0903be7 100644 --- a/calc.py +++ b/calc.py @@ -168,4 +168,8 @@ def run(self): def divide(a, b): - return a / b \ No newline at end of file + return a / b + + +def calculate_expression(expr): + return eval(expr) \ No newline at end of file From 2155f7fa0e81c35eab846ff78d4ba31f19540cd8 Mon Sep 17 00:00:00 2001 From: hjjj1 <2657916031@qq.com> Date: Wed, 3 Jun 2026 17:51:02 +0800 Subject: [PATCH 3/5] Add unsafe code examples for Graphite review --- calc.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/calc.py b/calc.py index 0903be7..8f43fa2 100644 --- a/calc.py +++ b/calc.py @@ -172,4 +172,20 @@ def divide(a, b): def calculate_expression(expr): - return eval(expr) \ No newline at end of file + # Intentionally unsafe demo code for Graphite review + return eval(expr) + + +def load_user_file(filename): + # Intentionally unsafe demo code for path traversal review + with open(filename, "r") as f: + return f.read() + + +def save_history(expression, result): + # Intentionally weak error handling demo + try: + with open("history.txt", "a") as f: + f.write(expression + "=" + result + "\n") + except: + pass \ No newline at end of file From 502345b7dde1513e2b51ef87c094ff23de445c55 Mon Sep 17 00:00:00 2001 From: hjjj1 <2657916031@qq.com> Date: Wed, 3 Jun 2026 18:12:25 +0800 Subject: [PATCH 4/5] Add risky code examples for Graphite review --- calc.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/calc.py b/calc.py index 8f43fa2..0f546a3 100644 --- a/calc.py +++ b/calc.py @@ -172,18 +172,22 @@ def divide(a, b): def calculate_expression(expr): - # Intentionally unsafe demo code for Graphite review return eval(expr) +def admin_login(username, password): + admin_password = "123456" + if username == "admin" and password == admin_password: + return True + return False + + def load_user_file(filename): - # Intentionally unsafe demo code for path traversal review with open(filename, "r") as f: return f.read() def save_history(expression, result): - # Intentionally weak error handling demo try: with open("history.txt", "a") as f: f.write(expression + "=" + result + "\n") From 6c42e1ea6040ca24cd5259c34c298d8c61e95420 Mon Sep 17 00:00:00 2001 From: hjjj1 <2657916031@qq.com> Date: Wed, 3 Jun 2026 18:23:52 +0800 Subject: [PATCH 5/5] Add risky code examples to trigger AI review --- calc.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/calc.py b/calc.py index 0f546a3..395e28c 100644 --- a/calc.py +++ b/calc.py @@ -168,14 +168,17 @@ def run(self): def divide(a, b): + # 没有处理 b=0 的情况,可能导致 ZeroDivisionError return a / b def calculate_expression(expr): + # 直接执行用户输入,容易造成代码注入 return eval(expr) def admin_login(username, password): + # 硬编码密码,不安全 admin_password = "123456" if username == "admin" and password == admin_password: return True @@ -183,13 +186,31 @@ def admin_login(username, password): def load_user_file(filename): + # 文件路径未校验,可能导致路径遍历攻击 with open(filename, "r") as f: return f.read() def save_history(expression, result): try: + # 直接吞掉异常,可能隐藏 bug with open("history.txt", "a") as f: f.write(expression + "=" + result + "\n") except: - pass \ No newline at end of file + pass + + +def unsafe_divide(a, b): + # 另一个不安全的除法示例,触发 review 建议 + if b == 0: + return "Error" + return a / b + + +def risky_eval(expr): + # eval 演示危险操作 + try: + return eval(expr) + except Exception: + # 捕获所有异常但不处理 + return "Invalid expression" \ No newline at end of file