`lean_compacted_region_read` SIGSEGV when `data_size < sizeof(object_offset)` and `num_closure_offsets == 0`
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Đọc phần xác thực khung phần trong src/library/module.cpp quanh dòng 600–626, đặc biệt là các bước kiểm tra data_size và num_closure_offsets của lean_compacted_region_read. Tái hiện sự cố bằng trường hợp TruncatedDataSize.lean được cung cấp, sau đó xác minh rằng reader từ chối dữ liệu nhỏ hơn một object_offset bằng IO.Error thay vì gặp sự cố.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Prerequisites
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly - When reporting a perceived soundness bug: Does it affect
lake check --paranoid?
If in doubt, please reach out on [email protected] for responsible disclosure.
Description
PR #16737 (fix: report truncated .olean files as errors) added section-framing validation in lean_compacted_region_read (src/library/module.cpp:600–626) to reject truncated .olean files cleanly instead of reading out of bounds.
However, lean_compacted_region_read checks data_size > static_cast<size_t>(end - p) (line 609), while the lower-bound check data_size < sizeof(void*) only appears inside if (num_closure_offsets > 0) (line 622).
When num_closure_offsets == 0 and data_size < sizeof(object_offset) (for example data_size = 0 or 4), framing validation succeeds and region_reader::read() immediately dereferences an 8-byte root object_offset at m_begin, reading past the data section / buffer and crashing with SIGSEGV.
Context
Found while reviewing the .olean section-framing check introduced in PR #16737.
Steps to Reproduce
- Save the following self-contained file as
TruncatedDataSize.lean:
import Lean
open Lean
unsafe def main : IO Unit := do
IO.FS.withTempFile fun _ file => do
let _ ← CompactedRegion.save file `EdgeTest ("hello" : String) #[] none false
let bytes ← IO.FS.readBinFile file
-- Keep 88-byte header, set data_size = 4 (< sizeof(object_offset) = 8), num_closure_offsets = 0
let mut bad := bytes.extract 0 88
for b in [4, 0, 0, 0, 0, 0, 0, 0] do bad := bad.push b.toUInt8
for b in [0xef, 0xbe, 0xad, 0xde] do bad := bad.push b.toUInt8
for _ in [0:4] do bad := bad.push 0
IO.FS.writeBinFile file bad
let (s, _) ← CompactedRegion.read (α := String) file #[]
IO.println s.length
- Run with Lean nightly:
lean --run TruncatedDataSize.lean
Expected behavior: CompactedRegion.read rejects the file with an IO.Error reporting that the compacted region data section is too small / truncated (data_size < sizeof(object_offset)), consistent with PR #16737.
Actual behavior: lean crashes with Segmentation fault (core dumped) (exit code 139).
Versions
Lean (version 4.38.0-nightly-2026-11-26, x86_64-unknown-linux-gnu, commit e1228b8b45918ece1a00d68e5fc5e6a685ca59ee, Release)
Lean (version 4.36.0, x86_64-unknown-linux-gnu, commit 611c117bfaf7b7ae1cfcf246ce6fba31e8f509e9, Release)
Ubuntu 24.04.4 LTS (Linux 6.17.0-1022-azure x86_64)
Additional Information
Suggested 2-line fix in src/library/module.cpp right after if (data_size > static_cast<size_t>(end - p)):
if (data_size < sizeof(object_offset))
throw exception("compacted region data section too small");
- Ngôn ngữ chính
- Lean
- Star
- 10.5k
- Fork
- 1.2k
- Merge trung bình
- 17 giờ 55 phút
- Pull request đã merge (30 ngày)
- 356
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của leanprover/lean4
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 86/100
leanprover/lean4#16886 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
leanprover/lean4#16842 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
leanprover/lean4#16841 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
leanprover/lean4#16840 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
doc: stray "public" in Bool and HEq documentationCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
leanprover/lean4#16825 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của leanprover/lean4
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
hyperledger/SmartBFT#803 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
possible bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Mintplex-Labs/anything-llm#7388 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
kronos:develop:queued priority:P0
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
[typescript] BasicAuth.fromAuthorizationHeader accepts headers without the Basic scheme prefixĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement severity:low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Battle-Cattle/BCUK-Bot-4#1252 ·
Maintainer thường phản hồi trong vòng 1 ngày