Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def run_quine(filepath):
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
# (中严重)子进程调用未设置超时:如果某个示例意外进入死循环/阻塞,这里会导致 demo 永久卡住。
# 建议:communicate(timeout=...) 或改用 subprocess.run(..., timeout=...)
stdout, stderr = result.communicate()
output = stdout.decode('utf-8', errors='replace')

Expand Down Expand Up @@ -115,6 +117,7 @@ def demo_iterative_quine():
stdout=subprocess.PIPE,
env=env
)
# (中严重)同上:此处同样没有超时保护,链式/生成式 Quine 一旦异常挂起会卡住整个演示。
b_output, _ = result.communicate()

# 安全解码
Expand Down
4 changes: 4 additions & 0 deletions enhanced_quine.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def load_config():
with open('config.json', 'r') as f:
return json.load(f)
except:
# (中严重)裸 except 会吞掉 config.json 不存在/JSON 格式错误/权限等问题,导致真实原因不可见。
# 建议:至少区分 FileNotFoundError / json.JSONDecodeError,或打印告警信息。
return {}

def run_quine():
Expand All @@ -19,6 +21,8 @@ def run_quine():
s='s=%r;print(s%%s)';print(s%s)

if lang == 'zh':
# (中严重)配置分支目前未实现任何行为(pass),配置对输出无实际影响;与“增强版特性”描述可能不一致。
# 若计划引入插件/配置驱动输出,需要把配置值纳入 quine 字符串本身,否则会破坏严格 Quine 性质。
# This print would technically break the "strict" Quine property
# unless it's part of the quine string itself.
# Ideally, a configurable Quine would inject the config into the source string.
Expand Down
5 changes: 5 additions & 0 deletions generators/quine_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ def generate_quine(code: str) -> str:

# Quine 验证代码
if '--verify' in __import__('sys').argv:
# (高严重)这里的验证逻辑不成立:
# - original 是“当前文件源码”(包含模板、注释、data 等全部内容)
# - output 却被设置成 data(仅为“原始代码片段”字符串),并不是程序运行时 stdout 输出
# 因此 original == output 基本必然为 False,验证结果不可信。
# 建议:用子进程运行当前文件捕获 stdout,与 original 做换行规范化后比较。
import hashlib
with open(__file__, 'r') as f:
original = f.read()
Expand Down