SIGSEGV (exit 134) in bundled `rightstr()` when the length argument is a large negative number
Maintainer thường phản hồi trong vòng 1 ngày
@sarthakdev143-lite đang làm issue này rồi.
Từ ngày 14/11/2026.
- #1509 của @sarthakdev143-lite — đang mở
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 38/100
Hướng nghiên cứu
Start by reproducing with the one-line SELECT rightstr('abcdef', -1000000000) through the JDBC driver, then find rightstr in the bundled contrib extension-functions.c, focusing on the negative-length branch. The fix belongs in that C code, which the native library build compiles, so you will need to build libsqlitejdbc locally. Done means a large negative length returns an empty string or a clean error with no SIGSEGV, while small negatives still behave as before.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
A single SELECT rightstr(<text>, <large negative>) kills the whole JVM process with SIGSEGV — no Java exception can catch it, no SQLITE_NOMEM is returned, the process just dies (exit code 134).
rightstr is not a core SQLite function; it is supplied by the extension-functions code compiled into the native library shipped in this jar (libsqlitejdbc.dylib). Only the negative length branch of rightstr crashes: small negatives return an empty string, magnitudes ≥ ~2e8 segfault. Positive lengths of the same magnitude and leftstr with the same argument stay clean.
To Reproduce
SELECT rightstr('abcdef', -1000000000);
Connection c = DriverManager.getConnection("jdbc:sqlite::memory:");
try (ResultSet r = c.createStatement()
.executeQuery("SELECT rightstr('abcdef', -1000000000)")) {
while (r.next()) { }
}
java -cp "sqlite-jdbc-<version>.jar:." Repro
echo $? # 134
Expected behavior
Same as small negative arguments: an empty string (rightstr('abcdef', -1) returns length 0). At worst a clean error such as SQLITE_NOMEM / SQLITE_TOOBIG, as happens for positive lengths and for replicate('abcdef', 2147483647).
Logs
JVM crash report (hs_err_pid*.log):
# SIGSEGV (0xb) at pc=0x0000000104045a74
# Problematic frame:
# C [sqlite-3.54.1.0-...-libsqlitejdbc.dylib+0x1da74]
Native frames:
C libsqlitejdbc.dylib+0x1da74
C libsqlitejdbc.dylib+0x34e70
C libsqlitejdbc.dylib+0xbebc
J org.sqlite.core.NativeDB.step(J)I
J org.sqlite.core.DB.execute(J[Ljava/lang/Object;)I
J org.sqlite.core.JDBC3Statement.executeQuery
The crash happens inside SQLite expression evaluation (step), not in the JDBC wrapper.
Environment (please complete the following information)
- OS: macOS 15.6.1 (24G90)
- CPU architecture: arm64
- sqlite-jdbc version: 3.54.1.0 (bundled SQLite 3.54.1), JDK 25.0.1+8
Additional context
Stability — one fresh JVM per run, same single statement:
| length argument | result |
|---|---|
| -1e6 / -1e7 / -5e7 / -1e8 | no crash |
| -2e8 | 2/8 crash |
| -3e8 | 7/8 crash |
| -5e8 / -8e8 / -1e9 / -1.5e9 / -2e9 | 8/8 crash |
| INT64_MIN (-9223372036854775808) | 0/2 crash |
Reproduced across driver versions with -1000000000 (3 runs each): 3.49.1.0 → 3/3, 3.51.2.0 → 3/3, 3.53.4.0 → 3/3, 3.54.1.0 → 3/3.
Control group, same magnitude, no crash:
| statement | result |
|---|---|
leftstr('abcdef', -1000000000) |
0/5 |
substr('abcdef', -200000000) |
0/3 |
rightstr('abcdef', 200000000) |
0/3 |
padl('abcdef', 200000000, 'x') |
0/3 |
padr('abcdef', 200000000, 'x') |
0/3 |
padc('abcdef', 2000000000) |
0/5 |
replicate('abcdef', 2147483647) |
clean SQLITE_NOMEM: a malloc() failed |
Since positive lengths of the same size only produce a clean SQLITE_NOMEM/SQLITE_TOOBIG, this is not memory exhaustion: the length/pointer computation on the negative branch goes out of bounds once |N| reaches roughly 2e8.
Suggested fix: handle N < 0 explicitly in rightstr (return an empty string or sqlite3_result_error), and check nByte > db->aLimit[SQLITE_LIMIT_LENGTH] before allocating, as core substr does.
rightstr is not core SQLite — it comes from contrib extension-functions.c, which SQLite itself does not maintain. The crash is inside libsqlitejdbc.dylib, which this project compiles and ships, hence the report here. Found by sqlancer PST mutation testing while probing function parameter domains.
- Ngôn ngữ chính
- Java
- Star
- 3.3k
- Fork
- 676
- Merge trung bình
- 1 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 18
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 xerial/sqlite-jdbc
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
xerial/sqlite-jdbc#1515 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
xerial/sqlite-jdbc#1514 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
xerial/sqlite-jdbc#1513 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
xerial/sqlite-jdbc#1512 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
triage
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
xerial/sqlite-jdbc#1483 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của xerial/sqlite-jdbc
Issue tương tự
-
vips-drift
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Stirling-Tools/JPDFium#300 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
hermes-queue
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 85/100
chrisalunlloyd2-sudo/mindpalace#403 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Guidelines: document how to build a use case against a local, unpublished Flow/browserless-test changeCó thể đã có người làm @totally-not-ai đã nhận hôm nay. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
vaadin/use-cases#452 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area/storage area/storage/sql
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Apicurio/apicurio-registry#11159 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Area/Configuration Type/Improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ballerina-platform/static-code-analysis-tool#217 ·
Maintainer thường phản hồi trong vòng 1 ngày