strlen and wcslen are bound as int, but C returns size_t
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
- 52/100
Hướng nghiên cứu
Start with the declarations and native stubs named in the issue: C.java and c.c for strlen, plus OS.java and os.c for wcslen. Trace the affected call sites in Font.java and Display.java, and compare with TextLayout.java's cast of g_utf16_strlen. Done means the Java return types and regenerated stubs preserve size_t appropriately, and call sites handle the wider result; the issue reports no tests or build run.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Two C entry points return a size_t and are declared int on the Java side. The stub casts the result down, so the C compiler has nothing to warn about, and nothing anywhere compares the Java declaration with the C one.
/* bundles/org.eclipse.swt/Eclipse SWT PI/common/library/c.c:358 */
rc = (jint)strlen((char *)arg0);
/* string.h */ size_t strlen(const char *);
/* bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c:9855 */
rc = (jint)wcslen((const wchar_t *)arg0);
/* wchar.h */ size_t wcslen(const wchar_t *);
The Java declarations:
/* Eclipse SWT PI/common/org/eclipse/swt/internal/C.java:144 */ public static final native int strlen (long s);
/* Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java:4554 */ public static final native int wcslen (long string);
What it can cause
On LP64 size_t is 64-bit and jint is 32-bit, so the top 32 bits are dropped unconditionally. For a string of 2 GiB or more the returned length is wrong — and wrong in the worst way, because the cast makes it a plausible small number rather than an obvious failure.
Every call site uses the value directly as a length:
/* Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java:189 */ int length = C.strlen(family);
/* Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java:3424 */ int length = OS.wcslen (sharedData);
I have not observed a failure and nothing was built or run. Whether a string that long reaches these calls is a question about SWT's own use, not about the declarations.
Suggested fix
SWT already models size_t as Java long everywhere else in the same file. C.java declares eighteen memmove overloads and memset, and every one takes a long annotated cast=(size_t):
/* C.java:141 */ public static final native long memset (long buffer, int c, long num); /* @param num cast=(size_t) */
strlen and wcslen are the only places size_t appears as a return, and the only two that use int. The repair would be to make them look like the rest — declare long and regenerate the stubs.
Call sites assign to int length, so each would need a cast or a wider local. TextLayout already writes one for the same kind of value:
/* Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java:655 */
lineEnd = (int)OS.g_utf16_strlen(ptr, -1);
Provenance
Reported as part of ongoing research into cross-language boundaries. Every line above was checked against master on 2026-08-23. No runtime observation; nothing was built or run.
wcslen is Win32-only, where size_t is 64-bit under LLP64 as well, so the narrowing holds on both data models.
- Ngôn ngữ chính
- Java
- Star
- 202
- Fork
- 206
- Merge trung bình
- 14 giờ 7 phút
- Pull request đã merge (30 ngày)
- 103
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không 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 eclipse-platform/eclipse.platform.swt
-
`SWT_AWT.initFrame` takes `(long, String)` in Java; the GTK native declares no `className` and the Cocoa native types it `const char *`Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
eclipse-platform/eclipse.platform.swt#3665 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
eclipse-platform/eclipse.platform.swt#3546 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
eclipse-platform/eclipse.platform.swt#3428 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 75/100
eclipse-platform/eclipse.platform.swt#3336 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
eclipse-platform/eclipse.platform.swt#3718 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của eclipse-platform/eclipse.platform.swt
Issue tương tự
-
Flight SQL JDBC parses boolean properties case-sensitively, silently disabling TLS for useEncryption=TRUECó thể đã có người làm @Arawoof06 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
apache/arrow-java#1357 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
apache/rocketmq-dashboard#6610 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
MetricsHub/metricshub-community#1396 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
L: java:gradle L: java:maven L: ruby:bundler T: bug 🐞
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
dependabot/dependabot-core#16547 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Citationcount column sorts alphabetically instead of numericallyCó thể đã có người làm @kpunia306 đã nhận hôm nay. Đang mởstatus: needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
JabRef/jabref#17459 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày