fix(ecs): reading a component grows the SparseArray, so a bad id can exhaust WASM memory

Đang mở
#491 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

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/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ệ
cpp, typescript, wasm
Lĩnh vực
backend, game-dev

Hướng nghiên cứu

Start with the cited SparseArray.hpp operator[] and the Registry.hpp getEntityComponent and add_component entry points. Trace how reads handle out-of-range ids and how component registration and entity liveness are checked. Reproduce the large-id and SIZE_MAX cases, then run the relevant ECS/WASM tests; done means reads cannot grow the array and invalid entity ids are rejected safely.

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

Mô tả

bug modules:ecs
Which package is this bug report for?

ecs

Issue description

getEntityComponent and the embind get(idx) use the non-const operator[], which resizes on read: one stale or garbage id (e.g. 1e9) aborts the WASM heap. add_component accepts ids that were never spawned, and reads register component types as a side effect. On wasm32, idx == SIZE_MAX makes idx + 1 overflow to 0.

Where:

Evidence:

reference_type operator[](size_type idx)
{
    if (idx >= _data.size()) { _data.resize(idx + 1); }
    return _data[idx];
}

Suggested fix: Use a read path that does not grow the array (return empty when out of range), and bounds-check add_component against _next_entity and the alive state.

Found during a code audit of main at be72076.

Code sample

No response

Versions
  • Engine main at be72076
  • pnpm 12.0.0, Node.js 26, Bun 1.3.14
Issue priority

Medium (should be fixed soon)

I have tested this issue on a development release

be72076

Ngôn ngữ chính
TypeScript
Star
7
Fork
2
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
17

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 NanoForge-dev/Engine

Tất cả issue của NanoForge-dev/Engine

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.