`Export.Parse` accepts a re-bound expr id and a 2nd JSON object on one line (lean4lean `--import` uses it)

未关闭
#64 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
backend

调研方向

Start with Export/Parse.lean and compare it with the core copy at src/LeanExport/Parse.lean, focusing on the duplicate expression ID and end-of-input checks described in the issue. Reproduce both malformed inputs using the provided scripts and verify that parsing rejects them; the issue’s done criteria are that neither malformed file is accepted.

由索引模型根据 Issue 内容生成。

描述

The parser in Export/Parse.lean (master df81913) accepts two kinds of malformed files that the copy in core (src/LeanExport/Parse.lean) rejects:

  1. an expr id bound twice (core: Expr index N bound twice)
  2. two JSON objects on one line; the 2nd is silently dropped (core: Invalid JSON: ... expected end of input)

lean4lean --import reads exports with this parser (its lake-manifest pins lean4export df81913), so it accepts both files. For (2) the dropped object can be a theorem that is then never checked.

Repro
-- Two.lean
def two : Nat := 2
theorem two_eq : two = 2 := rfl
lean Two.lean -o Two.olean
LEAN_PATH=$(lean --print-libdir):. leanexport Two -- two_eq > two.ndjson
python3 dupid.py  two.ndjson > dup-id.ndjson
python3 twoobj.py two.ndjson > two-objects.ndjson

dupid.py:

import json, sys
# bind the id of the literal `2` a 2nd time, to 3
L = open(sys.argv[1]).read().splitlines()
i = next(i for i, l in enumerate(L) if '"natVal":"2"' in l)
k = json.loads(L[i])["ie"]
L.insert(i + 1, json.dumps({"ie": k, "natVal": "3"}))
print("\n".join(L))

twoobj.py (the 2nd object is a theorem bad whose value is its own type):

import json, sys
# append a 2nd, ill-typed theorem `bad` to the line of `theorem two_eq`
L = open(sys.argv[1]).read().splitlines()
mx = max(json.loads(l).get("in", 0) for l in L)
for i, l in enumerate(L):
    o = json.loads(l)
    if "thm" in o:
        b = dict(o["thm"]); b["name"] = mx + 1; b["all"] = [mx + 1]
        b["value"] = b["type"]   # a type used as its own proof
        L[i] = l + json.dumps({"thm": b})
        L.insert(i, json.dumps({"in": mx + 1, "str": {"pre": 0, "str": "bad"}}))
        break
print("\n".join(L))
Result (nightly-2026-11-26 bundled checkers)
file leanchecker paranoid lean4lean nanoda con-leche con-ron
dup-id reject reject accept decline malformed (exit 3) malformed (exit 3)
two-objects reject reject accept reject malformed (exit 3) malformed (exit 3)

lean4lean prints checked 8 declarations for both. v4.36.0 gives the same, except that v4.36.0 con-leche/con-ron also accept dup-id.

Impact

leanexport doesn't write such files, and --paranoid still rejects (leanchecker). But anything that trusts Export.Parse alone can be fed a file whose content isn't what got checked. Porting the bound twice checks and the end-of-input check from core would fix both.

主要语言
Lean
星标
52
派生
30
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

leanprover/lean4export 的其他 Issue

查看 leanprover/lean4export 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。