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

オープン
#64 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

leanprover/lean4export のほかの issue

leanprover/lean4export の issue をすべて見る

似ている issue

Backend & API Design の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。