A native program crashes with SIGSEGV when a string or JSON builder grows past 4 MiB

Đang mở
#3,642 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@alantriesagain đang làm issue này rồi.

Từ ngày 14/11/2026.

  • #3643 của @alantriesagain — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
22/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c, linux, typescript

Hướng nghiên cứu

Start in scr_sa_run_move in scr_alloc.c, where the run is moved with mremap(..., MREMAP_MAYMOVE | MREMAP_FIXED, q) and the fallback memcpy(q, p, have) runs after a failed call. Reproduce with the 1760 x 2400-character JSON snippet from the issue, which should exit 139 today. Done means that snippet prints 4229281 and the slice without crashing, and that the fallback no longer writes to unmapped memory. PR #3643 already targets this, so review or coordinate there before starting a second fix.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

A compiled program dies with SIGSEGV when a string builder grows past 4 MiB, in scr_sa_run_move's fallback copy. Node runs the same program.

Environment

  • scriptc 0.4.12 from npm (the release's @scriptc/compiler under Node, linking @scriptc/runtime-linux-x64-gnu); upstream main at 3198190fb3 has the same code.
  • Linux 6.8.0 x86_64, glibc 2.39.

What happens

const lines: string[] = [];
for (let i = 0; i < 1760; i++) lines.push("x".repeat(2400));
const text = JSON.stringify(lines);
console.log(String(text.length));
console.log(text.slice(0, 8));

Node prints 4229281 and ["xxxxxx. The native build prints nothing and exits 139.

The backtrace from an unstripped build of a larger app that hit it (resuming a 5 MB transcript, which became one JSON text):

#0  __memcpy_evex_unaligned_erms
#1  scr_sa_run_move () at scr_alloc.c
#2  scr_mem_realloc_ref ()
#3  scr_str_regrow ()
#4  scr_jb_grow ()
#5  scr_jb_put_json_str ()
#6  scr_dyn_json_write ()
...
#9  scr_json_stringify_with ()

At the fault: p=0x387c00000, q=0x388400000, have=0x800000, n=0x800019. info proc mappings showed an unmapped hole at exactly [0x388400000, 0x388c00000), which is q to q + have.

Cause

scr_sa_run_move moves the run with mremap(p, have, have, MREMAP_MAYMOVE | MREMAP_FIXED, q). When the old run spans two mappings, the call fails. On Linux a failed MREMAP_FIXED has already unmapped the destination range, so the fallback memcpy(q, p, have) writes into unmapped memory.

#3595 (the native CLI segfaulting on a large program) may be the same crash, since the CLI builds large strings too. I have not checked that.

Ngôn ngữ chính
TypeScript
Star
6.6k
Fork
216
Merge trung bình
9 giờ 35 phút
Pull request đã merge (30 ngày)
775

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của vercel-labs/scriptc

Tất cả issue của vercel-labs/scriptc

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.