EmbeddedFont#embed crashes when postscriptName is a Uint8Array (Hermes / React Native)

Đang mở
#1,687 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.

  • #1753 của @pratik-desgn — đã đóng, không merge

Đá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
58/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, react-native
Lĩnh vực
mobile-dev

Hướng nghiên cứu

Kiểm tra EmbeddedFont#embed trong src/pdfkit quanh dòng của built bundle được báo cáo và lần theo cách postscriptName được sử dụng trong quá trình tạo PDF. Tái hiện lỗi với một font có tên là Uint8Array trên Hermes, sau đó xác minh rằng việc nhúng font hoàn tất mà không xảy ra TypeError của replaceAll.

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

Mô tả

In EmbeddedFont#embed (src/pdfkit, line ~32447 in the built bundle), the code assumes this.font.postscriptName is always a string:

const name = tag + '+' + this.font.postscriptName?.replaceAll(' ', '_');

However, fontkit's readString() returns a raw Uint8Array when TextDecoder doesn't support the requested encoding (e.g. x-mac-roman, utf-16be). This happens on Hermes (React Native), which only supports utf-8 and utf-16le.
This causes a TypeError: replaceAll is not a function at PDF generation time.

Suggested fix

const _psName = this.font.postscriptName;
const _psStr = typeof _psName === 'string'
  ? _psName
  : _psName instanceof Uint8Array
    ? Array.from(_psName, b => String.fromCharCode(b)).join('')
    : String(_psName || '');
const name = tag + '+' + _psStr.replace(/ /g, '_');

This handles all three cases (string, Uint8Array, null/undefined) and also replaces .replaceAll() with .replace(/ /g, '_') for broader engine compatibility.

Your environment

  • pdfkit: 0.17.2
  • pdfmake: 0.3.3
  • React Native: 0.81.4
  • Expo: 54.0.10
  • React: 19.1.0
  • JS Engine: Hermes
  • Node: 20.19.5
  • Platform: iOS / Android
Ngôn ngữ chính
JavaScript
Star
10.7k
Fork
1.2k
Merge trung bình
21 giờ 41 phút
Pull request đã merge (30 ngày)
27

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 foliojs/pdfkit

Tất cả issue của foliojs/pdfkit

Issue tương tự

Thêm issue về JavaScript

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.