autoinit is broken for `libsql_open_v3`
Maintainer thường phản hồi trong vòng 11 ngày
Chưa có ai nhận issue này.
Đá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
- 48/100
Hướng nghiên cứu
Bắt đầu trong libsql-sqlite3/src/main.c tại các đường dẫn libsql_open_v3 và openDatabase được tham chiếu trong issue, sau đó chạy testcase.cpp với AddressSanitizer. Công việc được xem là hoàn tất khi testcase không còn bị crash lúc libsql_open_v3 được gọi mà trước đó chưa gọi sqlite3_initialize, đồng thời vẫn giữ nguyên hành vi API được ghi chép.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hi, its documented that calling sqlite3_initialize is required before using certain other functions.
However the library also supports "autoinit" whereby, when necessary, sqlite3_initialize is automatically called in the process of executing those functions:
https://github.com/tursodatabase/libsql/blob/268d16933c595498a2131f812b0e09adef5fb47c/libsql-sqlite3/src/main.c#L200-L204
One such function is openDatabase which is used by the sqlite3_open* and libsql_open* APIs.
However, there is a potential issue with libsql_open_v3 as it tries to perform memory allocation before invoking openDatabase via a call to make_ref_counted_wal_manager:
https://github.com/tursodatabase/libsql/blob/268d16933c595498a2131f812b0e09adef5fb47c/libsql-sqlite3/src/main.c#L3860-L3874
Thus, while libsql_open_v3 intends to automatically initialize, it actually does it too late, leading to a crash.
(found via automated fuzzing)
The following testcase demonstrates the issue:
testcase.cpp
#include <cstdint>
extern "C" {
#include "sqlite3.h"
#include "sqlite3ext.h"
}
int main(){
libsql_wal_manager wm{};
wm.bUsesShm = 0;
// Provide non-NULL stubs for required callbacks
wm.xOpen = +[](wal_manager_impl*, sqlite3_vfs*, sqlite3_file*, int, long long, const char*, libsql_wal*)->int{return 1; };
wm.xClose = +[](wal_manager_impl*, wal_impl*, sqlite3*, int, int, unsigned char*)->int{ return 0; };
wm.xLogDestroy = +[](wal_manager_impl*, sqlite3_vfs*, const char*)->int{ return 0; };
wm.xLogExists = +[](wal_manager_impl*, sqlite3_vfs*, const char*, int *pResOut)->int{ if(!pResOut) return 1; *pResOut=0; return 0; };
wm.xDestroy = +[](wal_manager_impl*){};
wm.pData = nullptr;
const char *fname = ":memory:";
sqlite3 *db=nullptr;
int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
// This call crashes inside libsql_open_v3 with pc=0x0
int rc = libsql_open_v3(fname, &db, flags, nullptr, wm);
(void)rc; (void)db;
return 0;
}
crash report
==12==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x000000000000 bp 0x7ffd3c874770 sp 0x7ffd3c8746a8 T0)
==12==Hint: pc points to the zero page.
==12==The signal is caused by a READ memory access.
==12==Hint: address points to the zero page.
#0 0x0 (<unknown module>)
#1 0x5650461d476e in main /fuzz/workspace/test.cpp:22:12
#2 0x7faec1d67d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (<unknown module>)
- Ngôn ngữ chính
- C
- Star
- 17.3k
- Fork
- 562
- Merge trung bình
- 10 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Có Dockerfile hoặc 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 tursodatabase/libsql
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
tursodatabase/libsql#2320 ·
Maintainer thường phản hồi trong vòng 11 ngày
-
`cloudflare` feature: hrana streams are never closedCó thể đã có người làm @pcbeingused333 đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
tursodatabase/libsql#2312 ·
Maintainer thường phản hồi trong vòng 11 ngày
-
bottomless: finished S3 upload tasks are never reaped, so sqld memory grows by ~10 KB per WAL batchCó thể đã có người làm @pavanmanishd đã nhận 25 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
tursodatabase/libsql#2298 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 11 ngày
-
Rust local Row::get_value truncates embedded NUL TEXT and panics on malformed UTF-8 (0.9.30)Có thể đã có người làm @Sanjays2402 đã nhận 35 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
tursodatabase/libsql#2285 ·
Maintainer thường phản hồi trong vòng 11 ngày
-
libsql-ffi: broken builds under Nix on macOSCó thể đã có người làm @frectonz đã nhận 85 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
tursodatabase/libsql#2275 ·
Maintainer thường phản hồi trong vòng 11 ngày
Tất cả issue của tursodatabase/libsql
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
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 78/100
JulianKemmerer/PipelineC#395 ·
-
upstream-blocked
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
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 76/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
libretro/parallel-n64#858 ·